From 3c1174fd2a381b54cd80d2cb6efcb9ea76e0aec2 Mon Sep 17 00:00:00 2001 From: Tom McGuire Date: Fri, 29 Jul 2022 08:14:46 -0700 Subject: [PATCH] fix: schema migrations and omit empty transactions (#2739) * fix: schema migrations from 1.36.1 * fix: omit empty transaction from redux store --- android/app/build.gradle | 2 +- android/gradle.properties | 2 +- ios/celo.xcodeproj/project.pbxproj | 8 ++--- package.json | 2 +- src/redux/migrations.test.ts | 54 +++++++++++++++++++++++++--- src/redux/migrations.ts | 18 +++++++--- src/redux/store.test.ts | 2 +- src/redux/store.ts | 2 +- src/transactions/feed/queryHelper.ts | 8 +++-- test/schemas.ts | 44 +++++++++++++---------- 10 files changed, 104 insertions(+), 38 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index 138676038fb..8c18c321a38 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -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" diff --git a/android/gradle.properties b/android/gradle.properties index 54f785f8439..5e058a89d34 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -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 diff --git a/ios/celo.xcodeproj/project.pbxproj b/ios/celo.xcodeproj/project.pbxproj index d42e4806029..7efb561cdad 100644 --- a/ios/celo.xcodeproj/project.pbxproj +++ b/ios/celo.xcodeproj/project.pbxproj @@ -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 "; @@ -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; @@ -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; @@ -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; diff --git a/package.json b/package.json index 5f56eb78aae..1e9dd4a7f57 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@valora/wallet", - "version": "1.37.0", + "version": "1.37.1", "author": "Celo", "license": "Apache-2.0", "private": true, diff --git a/src/redux/migrations.test.ts b/src/redux/migrations.test.ts index 1adb371ea1e..01551794a79 100644 --- a/src/redux/migrations.test.ts +++ b/src/redux/migrations.test.ts @@ -31,7 +31,8 @@ import { v56Schema, v57Schema, v58Schema, - v61Schema, + v59Schema, + v62Schema, v7Schema, v8Schema, vNeg1Schema, @@ -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 = [] @@ -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 = {} diff --git a/src/redux/migrations.ts b/src/redux/migrations.ts index 95df5f4d060..ef3d36bd4cf 100644 --- a/src/redux/migrations.ts +++ b/src/redux/migrations.ts @@ -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 = { @@ -694,6 +695,15 @@ 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: [], @@ -701,28 +711,28 @@ export const migrations = { 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, diff --git a/src/redux/store.test.ts b/src/redux/store.test.ts index ba1296f541c..8a5231f8028 100644 --- a/src/redux/store.test.ts +++ b/src/redux/store.test.ts @@ -93,7 +93,7 @@ describe('store state', () => { Object { "_persist": Object { "rehydrated": true, - "version": 63, + "version": 64, }, "account": Object { "acceptedTerms": false, diff --git a/src/redux/store.ts b/src/redux/store.ts index d05ebe0758b..e917928585f 100644 --- a/src/redux/store.ts +++ b/src/redux/store.ts @@ -23,7 +23,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: 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'], diff --git a/src/transactions/feed/queryHelper.ts b/src/transactions/feed/queryHelper.ts index 936ee333c5c..ab46611f7b4 100644 --- a/src/transactions/feed/queryHelper.ts +++ b/src/transactions/feed/queryHelper.ts @@ -1,3 +1,4 @@ +import { isEmpty } from 'lodash' import { useState } from 'react' import { useAsync } from 'react-async-hook' import { useTranslation } from 'react-i18next' @@ -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)) } } diff --git a/test/schemas.ts b/test/schemas.ts index 4f9b9abbd6e..d3db38ea9b0 100644 --- a/test/schemas.ts +++ b/test/schemas.ts @@ -1385,11 +1385,6 @@ export const v59Schema = { ...v58Schema._persist, version: 59, }, - fiatConnect: { - quotes: [], - quotesLoading: false, - quotesError: null, - }, } export const v60Schema = { @@ -1398,9 +1393,10 @@ export const v60Schema = { ...v59Schema._persist, version: 60, }, - app: { - ...v59Schema.app, - showSwapMenuInDrawerMenu: false, + fiatConnect: { + quotes: [], + quotesLoading: false, + quotesError: null, }, } @@ -1410,9 +1406,9 @@ export const v61Schema = { ...v60Schema._persist, version: 61, }, - fiatConnect: { - ...v60Schema.fiatConnect, - transfer: null, + app: { + ...v60Schema.app, + showSwapMenuInDrawerMenu: false, }, } @@ -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, @@ -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 { - return v63Schema as Partial + return v64Schema as Partial }