Skip to content

Commit

Permalink
fix: schema migrations and omit empty transactions (#2739)
Browse files Browse the repository at this point in the history
* fix: schema migrations from 1.36.1

* fix: omit empty transaction from redux store
  • Loading branch information
MuckT authored Jul 29, 2022
1 parent 27e0875 commit 3c1174f
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 38 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ android {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode appVersionCode
versionName "1.37.0"
versionName "1.37.1"
multiDexEnabled true
testBuildType System.getProperty('testBuildType', 'debug')
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CELO_RELEASE_KEY_ALIAS=celo-key-alias

# Setting this manually based on version number until we have this deploying via Cloud Build
# Example: v1.5.1 deployment number 1 = 1005001001 (1 005 001 001)
VERSION_CODE=1021071621
VERSION_CODE=1021071622
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
Expand Down
8 changes: 4 additions & 4 deletions ios/celo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
CURRENT_PROJECT_VERSION = 102;
CURRENT_PROJECT_VERSION = 103;
ENABLE_BITCODE = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "arm64 ";
Expand All @@ -1301,7 +1301,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
MARKETING_VERSION = 1.37.0;
MARKETING_VERSION = 1.37.1;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand All @@ -1328,7 +1328,7 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
CURRENT_PROJECT_VERSION = 102;
CURRENT_PROJECT_VERSION = 103;
ENABLE_BITCODE = NO;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
Expand All @@ -1341,7 +1341,7 @@
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
MARKETING_VERSION = 1.37.0;
MARKETING_VERSION = 1.37.1;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@valora/wallet",
"version": "1.37.0",
"version": "1.37.1",
"author": "Celo",
"license": "Apache-2.0",
"private": true,
Expand Down
54 changes: 49 additions & 5 deletions src/redux/migrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import {
v56Schema,
v57Schema,
v58Schema,
v61Schema,
v59Schema,
v62Schema,
v7Schema,
v8Schema,
vNeg1Schema,
Expand Down Expand Up @@ -597,9 +598,52 @@ describe('Redux persist migrations', () => {
})

it('works for v58 to v59', () => {
const oldSchema = v58Schema
const oldTransactions = [
{
metadata: {
title: null,
comment: '',
subtitle: null,
image: null,
},
__typename: 'TokenTransferV2',
block: '14255636',
transactionHash: '0xf4e59db43c9051947ffe8a29a09c8f85dcf540699855166aa68f11cda3014b72',
type: 'RECEIVED',
amount: {
value: '0.01',
tokenAddress: '0x765de816845861e75a25fca122bb6898b8b1282a',
localAmount: {
currencyCode: 'USD',
exchangeRate: '1',
value: '0.01',
},
},
fees: null,
timestamp: 1658945996000,
address: '0xde33e71faecdead20e6a8af8f362d2236cba005f',
},
{},
]
const oldSchema = {
...v58Schema,
transactions: {
...v58Schema.transactions,
transactions: oldTransactions,
},
}
const migratedSchema = migrations[59](oldSchema)

const expectedSchema: any = _.cloneDeep(oldSchema)
expectedSchema.transactions.transactions = [oldTransactions[0]]

expect(migratedSchema).toMatchObject(expectedSchema)
})

it('works for v59 to v60', () => {
const oldSchema = v59Schema
const migratedSchema = migrations[60](oldSchema)

const expectedSchema: any = _.cloneDeep(oldSchema)
expectedSchema.fiatConnect = {}
expectedSchema.fiatConnect.quotes = []
Expand All @@ -609,9 +653,9 @@ describe('Redux persist migrations', () => {
expect(migratedSchema).toMatchObject(expectedSchema)
})

it('works for v61 to v62', () => {
const oldSchema = v61Schema
const migratedSchema = migrations[62](oldSchema)
it('works for v62 to v63', () => {
const oldSchema = v62Schema
const migratedSchema = migrations[63](oldSchema)

const expectedSchema: any = _.cloneDeep(oldSchema)
expectedSchema.app.superchargeTokenConfigByToken = {}
Expand Down
18 changes: 14 additions & 4 deletions src/redux/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { REMOTE_CONFIG_VALUES_DEFAULTS } from 'src/firebase/remoteConfigValuesDe
import { AddressToDisplayNameType } from 'src/identity/reducer'
import { VerificationStatus } from 'src/identity/types'
import { PaymentDeepLinkHandler } from 'src/merchantPayment/types'
import { TokenTransaction } from 'src/transactions/types'
import { Currency } from 'src/utils/currencies'

export const migrations = {
Expand Down Expand Up @@ -694,35 +695,44 @@ export const migrations = {
},
}),
59: (state: any) => ({
...state,
transactions: {
...state.transactions,
transactions: (state.transactions.transactions || []).filter(
(transaction: TokenTransaction) => Object.keys(transaction).length > 0
),
},
}),
60: (state: any) => ({
...state,
fiatConnect: {
quotes: [],
quotesLoading: false,
quotesError: null,
},
}),
60: (state: any) => ({
61: (state: any) => ({
...state,
app: {
...state.app,
showSwapMenuInDrawerMenu: REMOTE_CONFIG_VALUES_DEFAULTS.showSwapMenuInDrawerMenu,
},
}),
61: (state: any) => ({
62: (state: any) => ({
...state,
fiatConnect: {
...state.fiatConnect,
transfer: null,
},
}),
62: (state: any) => ({
63: (state: any) => ({
...state,
app: {
..._.omit(state.app, 'superchargeTokens'),
superchargeTokenConfigByToken: {},
},
}),
63: (state: any) => ({
64: (state: any) => ({
...state,
fiatConnect: {
...state.fiatConnect,
Expand Down
2 changes: 1 addition & 1 deletion src/redux/store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('store state', () => {
Object {
"_persist": Object {
"rehydrated": true,
"version": 63,
"version": 64,
},
"account": Object {
"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 @@ -23,7 +23,7 @@ const persistConfig: PersistConfig<RootState> = {
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: 63,
version: 64,
keyPrefix: `reduxStore-`, // the redux-persist default is `persist:` which doesn't work with some file systems.
storage: FSStorage(),
blacklist: ['networkInfo', 'alert', 'imports', 'supercharge'],
Expand Down
8 changes: 6 additions & 2 deletions src/transactions/feed/queryHelper.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { isEmpty } from 'lodash'
import { useState } from 'react'
import { useAsync } from 'react-async-hook'
import { useTranslation } from 'react-i18next'
Expand Down Expand Up @@ -78,10 +79,13 @@ export function useFetchTransactions(): QueryHookResult {

const returnedTransactions = result.data?.tokenTransactionsV2?.transactions
if (returnedTransactions?.length) {
addTransactions(returnedTransactions)
const nonEmptyTransactions = returnedTransactions.filter(
(returnedTransaction) => !isEmpty(returnedTransaction)
)
addTransactions(nonEmptyTransactions)
// We store non-paginated results in redux to show them to the users when they open the app.
if (!paginatedResult) {
dispatch(updateTransactions(returnedTransactions))
dispatch(updateTransactions(nonEmptyTransactions))
}
}

Expand Down
44 changes: 26 additions & 18 deletions test/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1385,11 +1385,6 @@ export const v59Schema = {
...v58Schema._persist,
version: 59,
},
fiatConnect: {
quotes: [],
quotesLoading: false,
quotesError: null,
},
}

export const v60Schema = {
Expand All @@ -1398,9 +1393,10 @@ export const v60Schema = {
...v59Schema._persist,
version: 60,
},
app: {
...v59Schema.app,
showSwapMenuInDrawerMenu: false,
fiatConnect: {
quotes: [],
quotesLoading: false,
quotesError: null,
},
}

Expand All @@ -1410,9 +1406,9 @@ export const v61Schema = {
...v60Schema._persist,
version: 61,
},
fiatConnect: {
...v60Schema.fiatConnect,
transfer: null,
app: {
...v60Schema.app,
showSwapMenuInDrawerMenu: false,
},
}

Expand All @@ -1422,8 +1418,20 @@ export const v62Schema = {
...v61Schema._persist,
version: 62,
},
fiatConnect: {
...v61Schema.fiatConnect,
transfer: null,
},
}

export const v63Schema = {
...v62Schema,
_persist: {
...v62Schema._persist,
version: 63,
},
app: {
..._.omit(v61Schema.app, 'superchargeTokens'),
..._.omit(v62Schema.app, 'superchargeTokens'),
superchargeTokenConfigByToken: {
[mockCusdAddress]: {
minBalance: 10,
Expand All @@ -1437,18 +1445,18 @@ export const v62Schema = {
},
}

export const v63Schema = {
...v62Schema,
export const v64Schema = {
...v63Schema,
_persist: {
...v62Schema._persist,
version: 63,
...v63Schema._persist,
version: 64,
},
fiatConnect: {
...v62Schema.fiatConnect,
...v63Schema.fiatConnect,
providers: null,
},
}

export function getLatestSchema(): Partial<RootState> {
return v63Schema as Partial<RootState>
return v64Schema as Partial<RootState>
}

0 comments on commit 3c1174f

Please sign in to comment.