-
-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(trading): update indexed db to trading
- Loading branch information
1 parent
83f851f
commit 574824a
Showing
13 changed files
with
81 additions
and
19 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
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
52 changes: 52 additions & 0 deletions
52
packages/suite/src/storage/migrations/trading/migrationCoinmarketToTrading.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,52 @@ | ||
import type { OnUpgradeFunc } from '@trezor/suite-storage'; | ||
|
||
import { Trade } from 'src/types/wallet/tradingCommonTypes'; | ||
|
||
import type { SuiteDBSchema } from '../../definitions'; | ||
|
||
export const migrationCoinmarketToTrading: OnUpgradeFunc<SuiteDBSchema> = async ( | ||
db, | ||
_oldVersion, | ||
_newVersion, | ||
transaction, | ||
) => { | ||
const oldStoreName = 'coinmarketTrades'; | ||
const newStoreName = 'tradingTrades'; | ||
|
||
// 1. Migration coinmarketTrades to tradingTrades | ||
// @ts-expect-error - old type | ||
if (db.objectStoreNames.contains(oldStoreName)) { | ||
// @ts-expect-error - old type | ||
const trades = transaction.objectStore(oldStoreName); | ||
let tradesCursor = await trades.openCursor(); | ||
|
||
const newTradesStore = db.createObjectStore(newStoreName, { keyPath: trades.keyPath }); | ||
|
||
while (tradesCursor) { | ||
const trade = tradesCursor.value as Trade; | ||
|
||
await tradesCursor.delete(); | ||
await newTradesStore.add(trade); | ||
|
||
tradesCursor = await tradesCursor.continue(); | ||
} | ||
|
||
// @ts-expect-error - old type | ||
db.deleteObjectStore(oldStoreName); | ||
} | ||
|
||
// 2. Update draft keys to trading | ||
const formDrafts = transaction.objectStore('formDrafts'); | ||
const formDraftsKeys = (await formDrafts.getAllKeys()).filter(key => | ||
key.includes('coinmarket'), | ||
); | ||
|
||
formDraftsKeys.forEach(async key => { | ||
const draft = await formDrafts.get(key); | ||
|
||
if (draft) { | ||
formDrafts.add(draft, key.replace('coinmarket', 'trading')); | ||
formDrafts.delete(key); | ||
} | ||
}); | ||
}; |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
export const FormDraftPrefixKeyValues = [ | ||
'coinmarket-buy', | ||
'coinmarket-sell', | ||
'coinmarket-exchange', | ||
'trading-buy', | ||
'trading-sell', | ||
'trading-exchange', | ||
'stake-eth', | ||
'unstake-eth', | ||
] as const; |