-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(suite-native): bnb to bsc migration
- Loading branch information
1 parent
cc18737
commit b2e6662
Showing
8 changed files
with
118 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { NetworkSymbol } from '@suite-common/wallet-config'; | ||
|
||
type NetworkSymbolOld = Exclude<NetworkSymbol, 'bsc'> | 'bnb'; | ||
|
||
export const migrateEnabledDiscoveryNetworkSymbols = ( | ||
oldEnabledDiscoveryNetworkSymbols: NetworkSymbol[], | ||
): NetworkSymbol[] => | ||
(oldEnabledDiscoveryNetworkSymbols as NetworkSymbolOld[]).map(networkSymbol => | ||
networkSymbol === 'bnb' ? 'bsc' : networkSymbol, | ||
); |
This file contains 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
type Account = { | ||
symbol: string; | ||
key: string; | ||
}; | ||
|
||
export const migrateAccountBnbToBsc = (oldAccounts: Account[] | undefined): Account[] | undefined => | ||
oldAccounts?.map(oldAccount => { | ||
const { key, symbol } = oldAccount; | ||
|
||
if (symbol !== 'bnb') return oldAccount; | ||
|
||
return { | ||
...oldAccount, | ||
key: key.replace('-bnb-', '-bsc-'), | ||
symbol: 'bsc', | ||
}; | ||
}); |
25 changes: 25 additions & 0 deletions
25
suite-native/storage/src/migrations/wallet/transactions/v2.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
type TransactionStub = { | ||
symbol: string; | ||
}; | ||
|
||
type AccountTransactionsType = { | ||
[x: string]: TransactionStub[]; | ||
}; | ||
|
||
export const migrateTransactionsBnbToBsc = ( | ||
oldTransactions: AccountTransactionsType | undefined, | ||
): AccountTransactionsType | undefined => { | ||
const newTransactions: AccountTransactionsType = {}; | ||
|
||
for (const oldKey in oldTransactions) { | ||
const oldTxns = oldTransactions[oldKey]; | ||
|
||
const newKey = oldKey.replace('-bnb-', '-bsc-'); | ||
newTransactions[newKey] = oldTxns.map(oldTxn => ({ | ||
...oldTxn, | ||
symbol: oldTxn.symbol.replace('bnb', 'bsc'), | ||
})); | ||
} | ||
|
||
return newTransactions; | ||
}; |
15 changes: 15 additions & 0 deletions
15
suite-native/storage/src/tests/migrations/discoveryV2.test.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { NetworkSymbol } from '@suite-common/wallet-config'; | ||
|
||
import { migrateEnabledDiscoveryNetworkSymbols } from '../../migrations/discovery/v2'; | ||
|
||
describe('migrateEnabledDiscoveryNetworkSymbols', () => { | ||
it('should migrate old enabled discovery network symbols - change bnb to bsc', () => { | ||
const oldEnabledDiscoveryNetworkSymbols = ['btc', 'eth', 'bnb', 'test'] as NetworkSymbol[]; | ||
|
||
const migratedAccounts = migrateEnabledDiscoveryNetworkSymbols( | ||
oldEnabledDiscoveryNetworkSymbols, | ||
); | ||
|
||
expect(migratedAccounts).toEqual(['btc', 'eth', 'bsc', 'test']); | ||
}); | ||
}); |