-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Wallet] Add redux migration v0 (#143)
- Loading branch information
Showing
4 changed files
with
145 additions
and
98 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { migrations } from 'src/redux/migrations' | ||
import { getLatestSchema } from 'test/schemas' | ||
|
||
describe('Redux persist migrations', () => { | ||
it('work for v-1 to v0', () => { | ||
const defaultSchema = getLatestSchema() | ||
const vNeg1Stub = { | ||
...defaultSchema, | ||
app: { | ||
...defaultSchema.app, | ||
numberVerified: true, | ||
inviteCodeEntered: true, | ||
}, | ||
} | ||
const migratedSchema = migrations[0](vNeg1Stub) | ||
expect(migratedSchema.invite.redeemComplete).toEqual(true) | ||
expect(migratedSchema.identity.startedVerification).toEqual(true) | ||
expect(migratedSchema.identity.askedContactsPermission).toEqual(true) | ||
expect(migratedSchema.identity.isLoadingImportContacts).toEqual(false) | ||
}) | ||
}) |
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,16 @@ | ||
export const migrations = { | ||
0: (state: any) => { | ||
return { | ||
...state, | ||
invite: { | ||
...state.invite, | ||
redeemComplete: state.app.inviteCodeEntered, | ||
}, | ||
identity: { | ||
startedVerification: state.app.numberVerified, | ||
askedContactsPermission: state.app.numberVerified, | ||
isLoadingImportContacts: false, | ||
}, | ||
} | ||
}, | ||
} |
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,104 +1,112 @@ | ||
import { RootState } from 'src/redux/reducers' | ||
|
||
const schemaVersions = [ | ||
// Default (version -1 schema) | ||
{ | ||
app: { | ||
inviteCodeEntered: false, | ||
loggedIn: false, | ||
numberVerified: false, | ||
error: null, | ||
dismissErrorAfter: null, | ||
language: null, | ||
doingBackupFlow: false, | ||
message: null, | ||
dismissMessageAfter: null, | ||
analyticsEnabled: true, | ||
}, | ||
networkInfo: { | ||
connected: true, | ||
}, | ||
send: { | ||
isSending: false, | ||
suggestedFee: '', | ||
recentPhoneNumbers: [], | ||
recipientCache: {}, | ||
}, | ||
goldToken: { | ||
balance: null, | ||
educationCompleted: false, | ||
lastFetch: null, | ||
}, | ||
stableToken: { | ||
balance: null, | ||
educationCompleted: false, | ||
lastFetch: null, | ||
}, | ||
home: { | ||
loading: false, | ||
notifications: [], | ||
}, | ||
medianator: { | ||
exchangeRate: '1', | ||
}, | ||
transactions: { | ||
standbyTransactions: [], | ||
}, | ||
web3: { | ||
isReady: false, | ||
syncProgress: 0, | ||
syncProgressData: { | ||
currentBlock: 0, | ||
highestBlock: 0, | ||
startBlock: 0, | ||
}, | ||
latestBlockNumber: 0, | ||
account: '0x0000000000000000000000000000000000007E57', | ||
commentKey: '0x0000000000000000000000000000000000008F68', | ||
gasPriceLastUpdated: 0, | ||
}, | ||
identity: { | ||
attestationCodes: [], | ||
numCompleteAttestations: 0, | ||
verificationFailed: false, | ||
addressToE164Number: {}, | ||
e164NumberToAddress: {}, | ||
startedVerification: false, | ||
askedContactsPermission: false, | ||
isLoadingImportContacts: false, | ||
}, | ||
account: { | ||
name: 'John Doe', | ||
e164PhoneNumber: '+14155556666', | ||
defaultCountryCode: '+1', | ||
contactDetails: { | ||
contactId: 'contactId', | ||
thumbnailPath: null, | ||
}, | ||
devModeActive: false, | ||
devModeClickCount: 0, | ||
photosNUXClicked: false, | ||
pincodeSet: false, | ||
accountCreationTime: 99999999999999, | ||
paymentRequests: [], | ||
showFakeData: false, | ||
backupCompleted: false, | ||
dismissedEarnRewards: false, | ||
dismissedInviteFriends: false, | ||
}, | ||
invite: { | ||
isSendingInvite: false, | ||
invitees: {}, | ||
redeemedInviteCode: '', | ||
redeemComplete: false, | ||
// Default (version -1 schema) | ||
const vNeg1Schema = { | ||
app: { | ||
inviteCodeEntered: false, | ||
loggedIn: false, | ||
numberVerified: false, | ||
error: null, | ||
dismissErrorAfter: null, | ||
language: null, | ||
doingBackupFlow: false, | ||
message: null, | ||
dismissMessageAfter: null, | ||
analyticsEnabled: true, | ||
}, | ||
networkInfo: { | ||
connected: true, | ||
}, | ||
send: { | ||
isSending: false, | ||
suggestedFee: '', | ||
recentPhoneNumbers: [], | ||
recipientCache: {}, | ||
}, | ||
goldToken: { | ||
balance: null, | ||
educationCompleted: false, | ||
lastFetch: null, | ||
}, | ||
stableToken: { | ||
balance: null, | ||
educationCompleted: false, | ||
lastFetch: null, | ||
}, | ||
home: { | ||
loading: false, | ||
notifications: [], | ||
}, | ||
medianator: { | ||
exchangeRate: '1', | ||
}, | ||
transactions: { | ||
standbyTransactions: [], | ||
}, | ||
web3: { | ||
isReady: false, | ||
syncProgress: 0, | ||
syncProgressData: { | ||
currentBlock: 0, | ||
highestBlock: 0, | ||
startBlock: 0, | ||
}, | ||
escrow: { | ||
sentEscrowedPayments: [], | ||
currentPaymentId: '', | ||
latestBlockNumber: 0, | ||
account: '0x0000000000000000000000000000000000007E57', | ||
commentKey: '0x0000000000000000000000000000000000008F68', | ||
gasPriceLastUpdated: 0, | ||
}, | ||
identity: { | ||
attestationCodes: [], | ||
numCompleteAttestations: 0, | ||
verificationFailed: false, | ||
addressToE164Number: {}, | ||
e164NumberToAddress: {}, | ||
}, | ||
account: { | ||
name: 'John Doe', | ||
e164PhoneNumber: '+14155556666', | ||
defaultCountryCode: '+1', | ||
contactDetails: { | ||
contactId: 'contactId', | ||
thumbnailPath: null, | ||
}, | ||
devModeActive: false, | ||
devModeClickCount: 0, | ||
photosNUXClicked: false, | ||
pincodeSet: false, | ||
accountCreationTime: 99999999999999, | ||
paymentRequests: [], | ||
showFakeData: false, | ||
backupCompleted: false, | ||
dismissedEarnRewards: false, | ||
dismissedInviteFriends: false, | ||
}, | ||
] | ||
invite: { | ||
isSendingInvite: false, | ||
invitees: {}, | ||
redeemedInviteCode: '', | ||
}, | ||
escrow: { | ||
sentEscrowedPayments: [], | ||
currentPaymentId: '', | ||
}, | ||
} | ||
|
||
const v0Schema = { | ||
...vNeg1Schema, | ||
identity: { | ||
...vNeg1Schema.identity, | ||
startedVerification: false, | ||
askedContactsPermission: false, | ||
isLoadingImportContacts: false, | ||
}, | ||
invite: { | ||
...vNeg1Schema.invite, | ||
redeemComplete: false, | ||
}, | ||
} | ||
|
||
export function getLatestSchema(): Partial<RootState> { | ||
return schemaVersions[schemaVersions.length - 1] as Partial<RootState> | ||
return v0Schema as Partial<RootState> | ||
} |