Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Commit

Permalink
Fix: legacy storage keys (#3170)
Browse files Browse the repository at this point in the history
* Fix: legacy storage keys

* Use CHAIN_ID
  • Loading branch information
katspaugh authored Dec 13, 2021
1 parent 0129da3 commit 1f5d4b7
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 57 deletions.
105 changes: 54 additions & 51 deletions src/logic/safe/utils/mocks/remoteConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,119 +65,119 @@
]
},
{
"transactionService": "https://safe-transaction-polygon.staging.gnosisdev.com",
"chainId": "137",
"chainName": "Polygon",
"shortName": "matic",
"transactionService": "https://safe-transaction.avalanche.gnosis.io",
"chainId": "43114",
"chainName": "Avalanche",
"shortName": "Avalanche",
"l2": true,
"description": "Test",
"description": "",
"rpcUri": {
"authentication": "API_KEY_PATH",
"value": "https://polygon-mainnet.infura.io/v3/"
"authentication": "NO_AUTHENTICATION",
"value": "https://api.avax.network/ext/bc/C/rpc"
},
"safeAppsRpcUri": {
"authentication": "API_KEY_PATH",
"value": "https://polygon-mainnet.infura.io/v3/"
"authentication": "NO_AUTHENTICATION",
"value": "https://api.avax.network/ext/bc/C/rpc"
},
"publicRpcUri": {
"authentication": "API_KEY_PATH",
"value": "https://polygon-mainnet.infura.io/v3/"
"authentication": "NO_AUTHENTICATION",
"value": "https://api.avax.network/ext/bc/C/rpc"
},
"blockExplorerUriTemplate": {
"address": "https://polygonscan.com/address/{{address}}",
"txHash": "https://polygonscan.com/tx/{{txHash}}",
"api": "https://api.polygonscan.com/api?module={{module}}&action={{action}}&address={{address}}&apiKey={{apiKey}}"
"address": "https://snowtrace.io/address/{{address}}",
"txHash": "https://snowtrace.io/tx/{{txHash}}",
"api": "https://api.snowtrace.io/api?module={{module}}&action={{action}}&address={{address}}&apiKey={{apiKey}}"
},
"nativeCurrency": {
"name": "Matic",
"symbol": "MATIC",
"name": "Avalanche",
"symbol": "AVAX",
"decimals": 18,
"logoUri": "https://safe-transaction-assets.staging.gnosisdev.com/chains/137/currency_logo.png"
"logoUri": "https://safe-transaction-assets.staging.gnosisdev.com/chains/43114/currency_logo.png"
},
"theme": {
"textColor": "#ffffff",
"backgroundColor": "#8248E5"
"backgroundColor": "#e84142"
},
"gasPrice": [
{
"type": "ORACLE",
"uri": "https://gasstation-mainnet.matic.network",
"gasParameter": "standard",
"gweiFactor": "1000000000.000000000"
}
],
"gasPrice": [],
"disabledWallets": [
"authereum",
"coinbase",
"fortmatic",
"keystone",
"lattice",
"ledger",
"opera",
"operaTouch",
"portis",
"torus",
"trezor",
"trust",
"walletLink"
"trust"
],
"features": [
"CONTRACT_INTERACTION",
"DOMAIN_LOOKUP",
"ERC721",
"SAFE_APPS",
"SAFE_TX_GAS_OPTIONAL"
]
},
{
"transactionService": "https://safe-transaction.avalanche.gnosis.io",
"chainId": "43114",
"chainName": "Avalanche",
"shortName": "Avalanche",
"transactionService": "https://safe-transaction-polygon.staging.gnosisdev.com",
"chainId": "137",
"chainName": "Polygon",
"shortName": "matic",
"l2": true,
"description": "",
"description": "Test",
"rpcUri": {
"authentication": "NO_AUTHENTICATION",
"value": "https://api.avax.network/ext/bc/C/rpc"
"authentication": "API_KEY_PATH",
"value": "https://polygon-mainnet.infura.io/v3/"
},
"safeAppsRpcUri": {
"authentication": "NO_AUTHENTICATION",
"value": "https://api.avax.network/ext/bc/C/rpc"
"authentication": "API_KEY_PATH",
"value": "https://polygon-mainnet.infura.io/v3/"
},
"publicRpcUri": {
"authentication": "NO_AUTHENTICATION",
"value": "https://api.avax.network/ext/bc/C/rpc"
"value": "https://polygon-rpc.com/"
},
"blockExplorerUriTemplate": {
"address": "https://snowtrace.io/address/{{address}}",
"txHash": "https://snowtrace.io/tx/{{txHash}}",
"api": "https://api.snowtrace.io/api?module={{module}}&action={{action}}&address={{address}}&apiKey={{apiKey}}"
"address": "https://polygonscan.com/address/{{address}}",
"txHash": "https://polygonscan.com/tx/{{txHash}}",
"api": "https://api.polygonscan.com/api?module={{module}}&action={{action}}&address={{address}}&apiKey={{apiKey}}"
},
"nativeCurrency": {
"name": "Avalanche",
"symbol": "AVAX",
"name": "Matic",
"symbol": "MATIC",
"decimals": 18,
"logoUri": "https://safe-transaction-assets.staging.gnosisdev.com/chains/43114/currency_logo.png"
"logoUri": "https://safe-transaction-assets.staging.gnosisdev.com/chains/137/currency_logo.png"
},
"theme": {
"textColor": "#ffffff",
"backgroundColor": "#333333"
"backgroundColor": "#8248E5"
},
"gasPrice": [],
"gasPrice": [
{
"type": "ORACLE",
"uri": "https://gasstation-mainnet.matic.network",
"gasParameter": "standard",
"gweiFactor": "1000000000.000000000"
}
],
"disabledWallets": [
"authereum",
"coinbase",
"fortmatic",
"keystone",
"lattice",
"ledger",
"opera",
"operaTouch",
"portis",
"torus",
"trezor",
"trust"
"trust",
"walletLink"
],
"features": [
"CONTRACT_INTERACTION",
"EIP1559",
"ERC721",
"SAFE_APPS",
"SAFE_TX_GAS_OPTIONAL"
Expand Down Expand Up @@ -205,7 +205,7 @@
"blockExplorerUriTemplate": {
"address": "https://optimistic.etherscan.io/address/{{address}}",
"txHash": "https://optimistic.etherscan.io/tx/{{txHash}}",
"api": "https://api.optimistic.etherscan.io/api?module={{module}}&action={{action}}&address={{address}}&apiKey={{apiKey}}"
"api": "https://api-optimistic.etherscan.io/api?module={{module}}&action={{action}}&address={{address}}&apiKey={{apiKey}}"
},
"nativeCurrency": {
"name": "Ether",
Expand Down Expand Up @@ -234,6 +234,9 @@
"walletLink"
],
"features": [
"CONTRACT_INTERACTION",
"ERC721",
"SAFE_APPS",
"SAFE_TX_GAS_OPTIONAL"
]
},
Expand Down
4 changes: 1 addition & 3 deletions src/logic/safe/utils/safeStorage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { getStoragePrefix, loadFromStorage, saveToStorage } from 'src/utils/storage'
import { SafeRecordProps } from 'src/logic/safe/store/models/safe'
import { getChainById } from 'src/config'
import { ChainId } from 'src/config/chain.d'

export const SAFES_KEY = 'SAFES'
Expand All @@ -12,8 +11,7 @@ export const loadStoredSafes = (): Promise<StoredSafes | undefined> => {
}

export const loadStoredNetworkSafeById = (id: ChainId): Promise<StoredSafes | undefined> => {
const chain = getChainById(id)
return loadFromStorage<StoredSafes>(SAFES_KEY, getStoragePrefix(chain.chainName))
return loadFromStorage<StoredSafes>(SAFES_KEY, getStoragePrefix(id))
}

export const saveSafes = async (safes: StoredSafes): Promise<void> => {
Expand Down
13 changes: 13 additions & 0 deletions src/utils/storage/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { getStoragePrefix } from '..'

describe('getStoragePrefix', () => {
it('saves a stringified value', () => {
expect(getStoragePrefix('137')).toBe('_immortal|v2_POLYGON__')
expect(getStoragePrefix('4')).toBe('_immortal|v2_RINKEBY__')
expect(getStoragePrefix('1')).toBe('_immortal|v2_MAINNET__')
expect(getStoragePrefix('100')).toBe('_immortal|v2_XDAI__')
expect(getStoragePrefix('246')).toBe('_immortal|v2_ENERGY_WEB_CHAIN__')
expect(getStoragePrefix('9358392457')).toBe('_immortal|v2_9358392457__')
expect(getStoragePrefix()).toBe('_immortal|v2_RINKEBY__')
})
})
24 changes: 21 additions & 3 deletions src/utils/storage/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
import { getChainName } from 'src/config'
import { _getChainId } from 'src/config'
import { ChainId, CHAIN_ID } from 'src/config/chain.d'
import Storage from './Storage'

// Legacy storage keys. New chains will use the chain id as prefix.
// @TODO: migrate them to chain ids.
const STORAGE_KEYS: Record<ChainId, string> = {
[CHAIN_ID.ETHEREUM]: 'MAINNET',
[CHAIN_ID.RINKEBY]: 'RINKEBY',
[CHAIN_ID.BSC]: 'BSC',
[CHAIN_ID.XDAI]: 'XDAI',
[CHAIN_ID.POLYGON]: 'POLYGON',
[CHAIN_ID.ENERGY_WEB_CHAIN]: 'ENERGY_WEB_CHAIN',
[CHAIN_ID.ARBITRUM]: 'ARBITRUM',
[CHAIN_ID.VOLTA]: 'VOLTA',
}

export const storage = new Storage(window.localStorage, '')

// We need this to update on run time depending on selected network name
export const getStoragePrefix = (chainName = getChainName()): string => `_immortal|v2_${chainName}__`
export const getStoragePrefix = (id = _getChainId()): string => {
const name = STORAGE_KEYS[id] || id
// Legacy ImmortalDB prefix
// @TODO: migrate it
return `_immortal|v2_${name}__`
}

export const loadFromStorage = async <T = unknown>(
key: string,
Expand Down

0 comments on commit 1f5d4b7

Please sign in to comment.