From c2a6eb8bc1b27d130bb89a0ecad503f488d60796 Mon Sep 17 00:00:00 2001 From: Finnian Jacobson-Schulte <140328381+finnian0826@users.noreply.github.com> Date: Fri, 6 Sep 2024 06:07:26 +1200 Subject: [PATCH] fix(earn): Update providerId for cached earn txs (#5867) ### Description Updated providerId for earn transactions from `aave-v3` to `aave` in the backend, but it didn't update the cached transactions. This should update the providerId for cached earn transactions stored in root state. ### Test plan Ran app locally and confirmed errors went away, pool provider name showed correctly ### Related issues - Fixes N/A ### Backwards compatibility Yes ### Network scalability If a new NetworkId and/or Network are added in the future, the changes in this PR will: - [X] Continue to work without code changes, OR trigger a compilation error (guaranteeing we find it when a new network is added) --- src/redux/migrations.test.ts | 31 +++++++++++++++++++++++++++++++ src/redux/migrations.ts | 24 ++++++++++++++++++++++++ src/redux/store.test.ts | 2 +- src/redux/store.ts | 2 +- test/schemas.ts | 10 +++++++++- 5 files changed, 66 insertions(+), 3 deletions(-) diff --git a/src/redux/migrations.test.ts b/src/redux/migrations.test.ts index d08f40a510..9df5c58049 100644 --- a/src/redux/migrations.test.ts +++ b/src/redux/migrations.test.ts @@ -55,6 +55,7 @@ import { v21Schema, v222Schema, v227Schema, + v228Schema, v28Schema, v2Schema, v35Schema, @@ -84,6 +85,7 @@ import { vNeg1Schema, } from 'test/schemas' import { + mockEarnDepositTransaction, mockInvitableRecipient, mockInvitableRecipient2, mockPositionsLegacy, @@ -1664,4 +1666,33 @@ describe('Redux persist migrations', () => { )) expect(migratedSchema).toStrictEqual(expectedSchema) }) + it('works from 228 to 229', () => { + const oldSchema = { + ...v228Schema, + transactions: { + ...v228Schema.transactions, + transactionsByNetworkId: { + ...v228Schema.transactions.transactionsByNetworkId, + [NetworkId['arbitrum-sepolia']]: [ + { ...mockEarnDepositTransaction, providerId: 'aave-v3' }, + ], + }, + standbyTransactions: [ + { + ...mockEarnDepositTransaction, + providerId: 'aave-v3', + status: TransactionStatus.Pending, + }, + ...v228Schema.transactions.standbyTransactions, + ], + }, + } + const migratedSchema = migrations[229](oldSchema) + const expectedSchema: any = _.cloneDeep(oldSchema) + expectedSchema.transactions.transactionsByNetworkId[ + NetworkId['arbitrum-sepolia'] + ][0].providerId = 'aave' + expectedSchema.transactions.standbyTransactions[0].providerId = 'aave' + expect(migratedSchema).toStrictEqual(expectedSchema) + }) }) diff --git a/src/redux/migrations.ts b/src/redux/migrations.ts index a5e1b63274..9bca232d53 100644 --- a/src/redux/migrations.ts +++ b/src/redux/migrations.ts @@ -1877,4 +1877,28 @@ export const migrations = { 'mtwAddress' ), }), + 229: (state: any) => { + const transactionsByNetworkId: any = {} + for (const networkId of Object.keys(state.transactions.transactionsByNetworkId)) { + const transactions = [] + for (const tx of state.transactions.transactionsByNetworkId[networkId]) { + ;(networkId === NetworkId['arbitrum-one'] || networkId === NetworkId['arbitrum-sepolia']) && + tx.providerId && + tx.providerId === 'aave-v3' + ? transactions.push({ ...tx, providerId: 'aave' }) + : transactions.push(tx) + } + transactionsByNetworkId[networkId] = transactions + } + return { + ...state, + transactions: { + ...state.transactions, + transactionsByNetworkId, + standbyTransactions: state.transactions.standbyTransactions.map((tx: any) => { + return tx.providerId && tx.providerId === 'aave-v3' ? { ...tx, providerId: 'aave' } : tx + }), + }, + } + }, } diff --git a/src/redux/store.test.ts b/src/redux/store.test.ts index c353e2c25a..3f62740dd9 100644 --- a/src/redux/store.test.ts +++ b/src/redux/store.test.ts @@ -98,7 +98,7 @@ describe('store state', () => { { "_persist": { "rehydrated": true, - "version": 228, + "version": 229, }, "account": { "acceptedTerms": false, diff --git a/src/redux/store.ts b/src/redux/store.ts index c1b1a1dfd0..ad2be010b8 100644 --- a/src/redux/store.ts +++ b/src/redux/store.ts @@ -21,7 +21,7 @@ const persistConfig: PersistConfig = { key: 'root', // default is -1, increment as we make migrations // See https://github.com/valora-inc/wallet/tree/main/WALLET.md#redux-state-migration - version: 228, + version: 229, keyPrefix: `reduxStore-`, // the redux-persist default is `persist:` which doesn't work with some file systems. storage: FSStorage(), blacklist: ['networkInfo', 'alert', 'imports', 'keylessBackup', 'jumpstart'], diff --git a/test/schemas.ts b/test/schemas.ts index bca129318b..5bbe87e934 100644 --- a/test/schemas.ts +++ b/test/schemas.ts @@ -3495,6 +3495,14 @@ export const v228Schema = { ), } +export const v229Schema = { + ...v228Schema, + _persist: { + ...v228Schema._persist, + version: 229, + }, +} + export function getLatestSchema(): Partial { - return v228Schema as Partial + return v229Schema as Partial }