Skip to content

Commit

Permalink
fix(earn): Update providerId for cached earn txs (#5867)
Browse files Browse the repository at this point in the history
### 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)
  • Loading branch information
finnian0826 authored Sep 5, 2024
1 parent 9c894f6 commit c2a6eb8
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 3 deletions.
31 changes: 31 additions & 0 deletions src/redux/migrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
v21Schema,
v222Schema,
v227Schema,
v228Schema,
v28Schema,
v2Schema,
v35Schema,
Expand Down Expand Up @@ -84,6 +85,7 @@ import {
vNeg1Schema,
} from 'test/schemas'
import {
mockEarnDepositTransaction,
mockInvitableRecipient,
mockInvitableRecipient2,
mockPositionsLegacy,
Expand Down Expand Up @@ -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)
})
})
24 changes: 24 additions & 0 deletions src/redux/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}),
},
}
},
}
2 changes: 1 addition & 1 deletion src/redux/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('store state', () => {
{
"_persist": {
"rehydrated": true,
"version": 228,
"version": 229,
},
"account": {
"acceptedTerms": false,
Expand Down
2 changes: 1 addition & 1 deletion src/redux/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const persistConfig: PersistConfig<ReducersRootState> = {
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'],
Expand Down
10 changes: 9 additions & 1 deletion test/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3495,6 +3495,14 @@ export const v228Schema = {
),
}

export const v229Schema = {
...v228Schema,
_persist: {
...v228Schema._persist,
version: 229,
},
}

export function getLatestSchema(): Partial<RootState> {
return v228Schema as Partial<RootState>
return v229Schema as Partial<RootState>
}

0 comments on commit c2a6eb8

Please sign in to comment.