Skip to content

Commit

Permalink
fix: new user will meet white screen after import address (#469)
Browse files Browse the repository at this point in the history
  • Loading branch information
vvvvvv1vvvvvv authored Jan 8, 2022
1 parent 0a76ffa commit 48161b2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 29 deletions.
4 changes: 2 additions & 2 deletions __tests__/migration/customTokenMigration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test('should migrate data', () => {
{ id: '0x9a78649501bbbac285ea4187299471b7ad4abd35', chain: 'eth' },
])
.then((result) => {
expect(result.preference.addedToken).toEqual({
expect(result!.preference.addedToken).toEqual({
'0x5853ed4f26a3fcea565b3fbc698bb19cdf6deb85': [
'bsc:0x9a78649501bbaac285ea4187299471b7ad4abd35',
'cro:0x9a78649501bbaac285ea4187299471b7ad4abd36',
Expand All @@ -44,6 +44,6 @@ const data1 = {
};
test('do nothing if empty', () => {
return customTokenMigration.migrator(data1).then((result) => {
expect(result.preference.addedToken).toEqual({});
expect(result!.preference.addedToken).toEqual({});
});
});
5 changes: 0 additions & 5 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -921,11 +921,6 @@ export class WalletController extends BaseController {
return this._setCurrentAccountFromKeyring(keyringInstance);
};

getWatchAddressPreference = (address: string) =>
preferenceService.getWatchAddressPreference(address);

setWatchAddressPreference = preferenceService.setWatchAddressPreference;

addTxExplainCache = (params: {
address: string;
chainId: number;
Expand Down
36 changes: 15 additions & 21 deletions src/background/service/preference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,21 @@ class PreferenceService {
if (!this.store.addedToken) {
this.store.addedToken = {};
}
if (!this.store.externalLinkAck) {
this.store.externalLinkAck = false;
}
if (!this.store.hiddenAddresses) {
this.store.hiddenAddresses = [];
}
if (!this.store.balanceMap) {
this.store.balanceMap = {};
}
if (!this.store.useLedgerLive) {
this.store.useLedgerLive = false;
}
if (!this.store.walletSavedList) {
this.store.walletSavedList = [];
}
};

getLastTimeSendToken = (address: string) => {
Expand Down Expand Up @@ -151,27 +166,6 @@ class PreferenceService {
return cloneDeep(this.store.hiddenAddresses);
};

getWatchAddressPreference = (address: string) => {
const key = address.toLowerCase();
if (
!this.store.watchAddressPreference ||
!this.store.watchAddressPreference[key]
)
return null;

return this.store.watchAddressPreference[key];
};

setWatchAddressPreference = (address: string, id: number) => {
if (!this.store.watchAddressPreference) {
this.store.watchAddressPreference = {};
}
this.store.watchAddressPreference = {
...this.store.watchAddressPreference,
[address.toLowerCase()]: id,
};
};

hideAddress = (type: string, address: string, brandName: string) => {
this.store.hiddenAddresses = [
...this.store.hiddenAddresses,
Expand Down
3 changes: 2 additions & 1 deletion src/migrations/customTokenMigration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export default {
_mockData?: any
) {
try {
if (data.preference === undefined) return undefined;

const addedTokens: Record<string, string[]> = {};
for (const addr in data.preference.addedToken) {
addedTokens[addr] = data.preference.addedToken[addr];
Expand All @@ -20,7 +22,6 @@ export default {
token.length === 42 &&
token.startsWith('0x')
);
console.log();
const resultTokens: { id: string; chain: string }[] =
process.env.NODE_ENV === 'test'
? _mockData
Expand Down

0 comments on commit 48161b2

Please sign in to comment.