Skip to content

Commit 0f211d5

Browse files
authored
Automatically switch to polkadot when unsuported network (#492)
1 parent e8c446b commit 0f211d5

File tree

5 files changed

+65
-14
lines changed

5 files changed

+65
-14
lines changed

packages/ui/cypress/tests/address-bar.cy.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ describe('Account address in the address bar', () => {
4444

4545
it('shows an error with 0 watched, 0 connected account, unknown linked address', () => {
4646
cy.visit(landingPageAddressUrl(testAccounts['Non Multisig Member 1'].address))
47-
landingPage.linkedAddressNotFound().should('contain.text', "The linked address can't be found")
47+
landingPage
48+
.linkedAddressNotFound()
49+
.should(
50+
'contain.text',
51+
"The linked address can't be found in your accounts or watched accounts on rococo"
52+
)
4853
topMenuItems.multiproxySelectorDesktop().should('not.exist')
4954
})
5055

@@ -58,7 +63,12 @@ describe('Account address in the address bar', () => {
5863
watchedAccounts: [publicKey]
5964
})
6065

61-
landingPage.linkedAddressNotFound().should('contain.text', "The linked address can't be found")
66+
landingPage
67+
.linkedAddressNotFound()
68+
.should(
69+
'contain.text',
70+
"The linked address can't be found in your accounts or watched accounts on rococo"
71+
)
6272
cy.url().should('include', testAccounts['Non Multisig Member 1'].address)
6373
topMenuItems.multiproxySelectorDesktop().should('be.visible')
6474
topMenuItems.multiproxySelectorInputDesktop().should('have.value', '')
@@ -82,7 +92,12 @@ describe('Account address in the address bar', () => {
8292
url: landingPageAddressUrl(testAccounts['Non Multisig Member 1'].address),
8393
watchedAccounts: [purePublicKey]
8494
})
85-
landingPage.linkedAddressNotFound().should('contain.text', "The linked address can't be found")
95+
landingPage
96+
.linkedAddressNotFound()
97+
.should(
98+
'contain.text',
99+
"The linked address can't be found in your accounts or watched accounts on rococo"
100+
)
86101
cy.url().should('include', testAccounts['Non Multisig Member 1'].address)
87102
topMenuItems.multiproxySelectorDesktop().should('be.visible')
88103
topMenuItems.multiproxySelectorInputDesktop().should('have.value', '')
@@ -107,7 +122,12 @@ describe('Account address in the address bar', () => {
107122
injectExtensionWithAccounts: [testAccounts['Multisig Member Account 1']]
108123
})
109124

110-
landingPage.linkedAddressNotFound().should('contain.text', "The linked address can't be found")
125+
landingPage
126+
.linkedAddressNotFound()
127+
.should(
128+
'contain.text',
129+
"The linked address can't be found in your accounts or watched accounts on rococo"
130+
)
111131
cy.url().should('include', nonMulitisigAccountAddress)
112132
topMenuItems.multiproxySelectorDesktop().should('be.visible')
113133
topMenuItems.multiproxySelectorInputDesktop().should('have.value', '')

packages/ui/cypress/tests/landing-messaging.cy.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { testAccounts } from '../fixtures/testAccounts'
2-
import { landingPageUrl } from '../fixtures/landingData'
2+
import { landingPageNetwork, landingPageUrl } from '../fixtures/landingData'
33
import { landingPage } from '../support/page-objects/landingPage'
44
import { topMenuItems } from '../support/page-objects/topMenuItems'
55
import { clickOnConnect } from '../utils/clickOnConnect'
@@ -47,7 +47,24 @@ describe('Landing Page Messaging', () => {
4747
cy.connectAccounts([testAccounts['Non Multisig Member 1'].address])
4848
landingPage
4949
.noMultisigFoundError()
50-
.should('contain.text', 'No multisig found for your accounts or watched accounts.')
50+
.should('contain.text', 'No multisig found for your accounts or watched accounts on rococo.')
51+
landingPage.createOneButton().should('be.visible').should('be.enabled')
52+
landingPage.watchAccountButton().should('be.visible').should('be.enabled')
53+
})
54+
55+
it('redirect to Polkadot if wrong network in url', () => {
56+
cy.visit(landingPageNetwork('wrong network'))
57+
cy.initWallet([testAccounts['Non Multisig Member 1']])
58+
clickOnConnect()
59+
// share the account that is not part of any multisig
60+
cy.connectAccounts([testAccounts['Non Multisig Member 1'].address])
61+
landingPage
62+
.noMultisigFoundError()
63+
.should(
64+
'contain.text',
65+
'No multisig found for your accounts or watched accounts on polkadot.'
66+
)
67+
cy.url().should('include', 'network=polkadot')
5168
landingPage.createOneButton().should('be.visible').should('be.enabled')
5269
landingPage.watchAccountButton().should('be.visible').should('be.enabled')
5370
})
@@ -60,7 +77,7 @@ describe('Landing Page Messaging', () => {
6077
})
6178
landingPage
6279
.noMultisigFoundError()
63-
.should('contain.text', 'No multisig found for your accounts or watched accounts.')
80+
.should('contain.text', 'No multisig found for your accounts or watched accounts on rococo.')
6481
landingPage.connectWalletButton().should('be.visible').should('be.enabled')
6582
landingPage.watchAccountButton().should('be.visible').should('be.enabled')
6683
})
@@ -76,7 +93,7 @@ describe('Landing Page Messaging', () => {
7693

7794
landingPage
7895
.noMultisigFoundError()
79-
.should('contain.text', 'No multisig found for your accounts or watched accounts.')
96+
.should('contain.text', 'No multisig found for your accounts or watched accounts on rococo.')
8097
landingPage.createOneButton().should('be.visible').should('be.enabled')
8198
landingPage.watchAccountButton().should('be.visible').should('be.enabled')
8299
})

packages/ui/src/components/ConnectCreateOrWatch.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@ import { createSearchParams, useNavigate, useSearchParams } from 'react-router-d
44
import { Button } from './library'
55
import { WATCH_ACCOUNT_ANCHOR } from '../pages/Settings/Settings'
66
import { useWatchedAddresses } from '../contexts/WatchedAddressesContext'
7+
import { useNetwork } from '../contexts/NetworkContext'
78

89
export const ConnectOrWatch = () => {
910
const { isAllowedToConnectToExtension, allowConnectionToExtension } = useAccounts()
1011
const { watchedAddresses } = useWatchedAddresses()
1112
const navigate = useNavigate()
1213
const [searchParams] = useSearchParams()
14+
const { selectedNetwork } = useNetwork()
1315

1416
return (
1517
<WrapperStyled>
1618
{isAllowedToConnectToExtension || watchedAddresses.length !== 0 ? (
1719
<div data-cy="label-no-multisig-found">
18-
No multisig found for your accounts or watched accounts.
20+
No multisig found for your accounts or watched accounts on{' '}
21+
<NetworkNameStyled>{selectedNetwork}</NetworkNameStyled>.
1922
</div>
2023
) : (
2124
<>
@@ -89,3 +92,7 @@ const ButtonWrapperStyled = styled('div')`
8992
margin: 0 0.5rem;
9093
}
9194
`
95+
96+
const NetworkNameStyled = styled('span')`
97+
text-transform: capitalize;
98+
`

packages/ui/src/contexts/NetworkContext.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useSearchParams } from 'react-router-dom'
33
import { NetworkInfo, SupportedNetworks, networkList } from '../constants'
44

55
const LOCALSTORAGE_SELECTED_NETWORK = 'multix.selectedNetwork'
6+
const DEFAULT_NETWORK = 'polkadot'
67

78
type NetworkContextProps = {
89
children: React.ReactNode | React.ReactNode[]
@@ -25,10 +26,9 @@ const NetworkContextProvider = ({ children }: NetworkContextProps) => {
2526

2627
const selectNetwork = useCallback(
2728
(network: string, shouldResetAccountAddress = false) => {
28-
const isNewSelectedNetworkSupported = isSupportedNetwork(network)
29-
30-
if (!isNewSelectedNetworkSupported) {
29+
if (!isSupportedNetwork(network)) {
3130
console.error('This network is not supported', network)
31+
selectNetwork(DEFAULT_NETWORK)
3232
return
3333
}
3434

@@ -64,7 +64,7 @@ const NetworkContextProvider = ({ children }: NetworkContextProps) => {
6464
return
6565
}
6666

67-
selectNetwork('kusama')
67+
selectNetwork(DEFAULT_NETWORK)
6868
}
6969
}, [searchParams, selectNetwork, selectedNetwork])
7070

packages/ui/src/hooks/useDisplayError.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ import { Center } from '../components/layout/Center'
1010
import { useWatchedAddresses } from '../contexts/WatchedAddressesContext'
1111
import { useMultiProxy } from '../contexts/MultiProxyContext'
1212
import { useSearchParams } from 'react-router-dom'
13+
import { useNetwork } from '../contexts/NetworkContext'
1314

1415
export const useDisplayError = () => {
1516
const { isExtensionError, isAccountLoading, ownAccountList, isAllowedToConnectToExtension } =
1617
useAccounts()
1718
const { watchedAddresses } = useWatchedAddresses()
1819
const { error: multisigQueryError, refetch, canFindMultiProxyFromUrl } = useMultiProxy()
1920
const [, setSearchParams] = useSearchParams()
21+
const { selectedNetwork } = useNetwork()
2022

2123
if (
2224
watchedAddresses.length === 0 &&
@@ -76,7 +78,8 @@ export const useDisplayError = () => {
7678
<ErrorMessageStyled>
7779
<ErrorOutlineIcon size={64} />
7880
<div data-cy="label-linked-address-not-found">
79-
The linked address can't be found in your accounts or watched accounts.
81+
The linked address can't be found in your accounts or watched accounts on{' '}
82+
<NetworkNameStyled>{selectedNetwork}</NetworkNameStyled>.
8083
</div>
8184
<Button
8285
data-cy="button-reset-linked-address"
@@ -119,3 +122,7 @@ const ErrorMessageStyled = styled('div')`
119122
margin-top: 1rem;
120123
}
121124
`
125+
126+
const NetworkNameStyled = styled('span')`
127+
text-transform: capitalize;
128+
`

0 commit comments

Comments
 (0)