This repository was archived by the owner on Nov 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 360
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5d78ee4
Fix: xDai -> Gnosis Chain
katspaugh f0762cf
chore: Update deployment link
71a8813
Rm "Safe" from deployment links
katspaugh ed9eb1c
chore: Add /xdai to root routes
2d4ddfb
chore: Extract root /xdai redirection
cbcfff5
build: Fixed xDai redirect + shortName root routes
fbd904f
chore: Fix shortName, update deploy + shortName
d3c9085
fix: shortName root routes + exact xDai redirect
2dc801b
Rm prod check
katspaugh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,44 +1,51 @@ | ||
| import { getShortName } from 'src/config' | ||
| import * as configUtils from 'src/logic/config/utils' | ||
| import { ZERO_ADDRESS } from 'src/logic/wallets/ethAddresses' | ||
| import { history, WELCOME_ROUTE } from 'src/routes/routes' | ||
| import { switchNetworkWithUrl } from '../history' | ||
| import { history } from 'src/routes/routes' | ||
| import { setChainIdFromUrl } from '../history' | ||
|
|
||
| describe('switchNetworkWithUrl', () => { | ||
| describe('setChainIdFromUrl', () => { | ||
| it('does not switch the network when there is no shortName in the url', () => { | ||
| const setChainIdMock = jest.spyOn(configUtils, 'setChainId') | ||
| const pathname = `/welcome` | ||
|
|
||
| history.push(`/rin:${ZERO_ADDRESS}`) | ||
| history.push(pathname) | ||
|
|
||
| switchNetworkWithUrl({ pathname: '/welcome' }) | ||
| const result = setChainIdFromUrl(pathname) | ||
|
|
||
| expect(result).toBe(false) | ||
| expect(setChainIdMock).not.toHaveBeenCalled() | ||
| }) | ||
| it('does not switch the network when the shortName has not changed', () => { | ||
| // chainId defaults to RINKEBY in non-production environments if it can't be read from LS | ||
| it('does not switch the network when the chainId has not changed', () => { | ||
| const setChainIdMock = jest.spyOn(configUtils, 'setChainId') | ||
| const pathname = `/rin:${ZERO_ADDRESS}` | ||
|
|
||
| history.push(`/rin:${ZERO_ADDRESS}`) | ||
| history.push(pathname) | ||
|
|
||
| switchNetworkWithUrl(history.location) | ||
| const result = setChainIdFromUrl(pathname) | ||
|
|
||
| expect(result).toBe(true) | ||
| expect(setChainIdMock).not.toHaveBeenCalled() | ||
| }) | ||
| it('switches the network when the shortName changes', () => { | ||
| // chainId defaults to RINKEBY in non-production environments if it can't be read from LS | ||
| const setChainIdMock = jest.spyOn(configUtils, 'setChainId') | ||
| const pathname = `/eth:${ZERO_ADDRESS}` | ||
|
|
||
| history.push(`/eth:${ZERO_ADDRESS}`) | ||
| history.push(pathname) | ||
|
|
||
| switchNetworkWithUrl(history.location) | ||
| const result = setChainIdFromUrl(pathname) | ||
|
|
||
| expect(result).toBe(true) | ||
| expect(setChainIdMock).toHaveBeenCalled() | ||
| }) | ||
| it('redirects to the Welcome page when incorrect shortName is in the URL', () => { | ||
| history.push(`/fakechain:${ZERO_ADDRESS}`) | ||
| const setChainIdMock = jest.spyOn(configUtils, 'setChainId') | ||
| const pathname = `/fakechain:${ZERO_ADDRESS}` | ||
|
|
||
| history.push(pathname) | ||
|
|
||
| switchNetworkWithUrl(history.location) | ||
| const result = setChainIdFromUrl(pathname) | ||
|
|
||
| expect(history.location.pathname).toBe(WELCOME_ROUTE) | ||
| expect(result).toBe(false) | ||
| expect(setChainIdMock).not.toHaveBeenCalled() | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,20 @@ | ||
| import { LocationDescriptorObject } from 'history' | ||
| import { getShortName } from 'src/config' | ||
| import { _getChainId } from 'src/config' | ||
| import { getChains } from 'src/config/cache/chains' | ||
| import { setChainId } from 'src/logic/config/utils' | ||
| import { hasPrefixedSafeAddressInUrl, extractPrefixedSafeAddress, history, WELCOME_ROUTE } from 'src/routes/routes' | ||
| import { DEFAULT_CHAIN_ID } from './constants' | ||
| import { hasPrefixedSafeAddressInUrl, extractPrefixedSafeAddress } from 'src/routes/routes' | ||
|
|
||
| export const switchNetworkWithUrl = ({ pathname }: LocationDescriptorObject): void => { | ||
| if (!hasPrefixedSafeAddressInUrl()) { | ||
| return | ||
| } | ||
| export const setChainIdFromUrl = (pathname: string): boolean => { | ||
| if (!hasPrefixedSafeAddressInUrl()) return false | ||
|
|
||
| const { shortName } = extractPrefixedSafeAddress(pathname) | ||
| const currentShortName = getShortName() | ||
|
|
||
| if (shortName === currentShortName) { | ||
| return | ||
| } | ||
|
|
||
| const chainId = getChains().find((chain) => chain.shortName === shortName)?.chainId | ||
|
|
||
| if (!chainId) { | ||
| setChainId(DEFAULT_CHAIN_ID) | ||
| history.push(WELCOME_ROUTE) | ||
| return | ||
| if (chainId) { | ||
| if (chainId !== _getChainId()) { | ||
| setChainId(chainId) | ||
| } | ||
| return true | ||
| } | ||
|
|
||
| setChainId(chainId) | ||
| return false | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also removed
limit: 100.