Skip to content

Commit

Permalink
OK-10944: fix account is deleted but account selector is not refreshed (
Browse files Browse the repository at this point in the history
  • Loading branch information
kwoktung authored Jul 19, 2022
1 parent ffe04d5 commit 93cd13c
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/kit/src/background/services/ServiceAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ class ServiceAccount extends ServiceBase {
},
);
this.backgroundApi.walletConnect.notifySessionChanged();
// emit at next tick
setTimeout(() => {
appEventBus.emit(AppEventBusNames.AccountChanged);
}, 10);
}

@backgroundMethod()
Expand Down
5 changes: 5 additions & 0 deletions packages/kit/src/background/services/ServiceNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import {
Network,
UpdateNetworkParams,
} from '@onekeyhq/engine/src/types/network';
import {
AppEventBusNames,
appEventBus,
} from '@onekeyhq/shared/src/eventBus/appEventBus';

import {
GeneralInitialState,
Expand Down Expand Up @@ -61,6 +65,7 @@ class ServiceNetwork extends ServiceBase {
},
);
this.backgroundApi.walletConnect.notifySessionChanged();
appEventBus.emit(AppEventBusNames.NetworkChanged);
}

@backgroundMethod()
Expand Down
24 changes: 23 additions & 1 deletion packages/kit/src/background/services/ServiceToken.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import {
AppEventBusNames,
appEventBus,
} from '@onekeyhq/shared/src/eventBus/appEventBus';

import {
TokenInitialState,
setAccountTokens,
Expand All @@ -7,10 +12,27 @@ import {
} from '../../store/reducers/tokens';
import { backgroundClass, backgroundMethod } from '../decorators';

import ServiceBase from './ServiceBase';
import ServiceBase, { IServiceBaseProps } from './ServiceBase';

@backgroundClass()
export default class ServiceToken extends ServiceBase {
constructor(props: IServiceBaseProps) {
super(props);
appEventBus.on(
AppEventBusNames.NetworkChanged,
this.refreshTokenBalance.bind(this),
);
}

refreshTokenBalance() {
const { appSelector } = this.backgroundApi;
const activeAccountId = appSelector((s) => s.general.activeAccountId);
const activeNetworkId = appSelector((s) => s.general.activeNetworkId);
if (activeAccountId && activeNetworkId) {
this.fetchTokenBalance({ activeAccountId, activeNetworkId });
}
}

@backgroundMethod()
async fetchTokens({
activeAccountId,
Expand Down
2 changes: 2 additions & 0 deletions packages/kit/src/views/ManagerAccount/AccountInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ const ManagerAccountModal: FC = () => {
accountId,
undefined,
() => {
refreshAccounts?.();
if (navigation.canGoBack()) navigation.goBack();
},
);
Expand All @@ -172,6 +173,7 @@ const ManagerAccountModal: FC = () => {
accountId,
pwd,
() => {
refreshAccounts?.();
if (navigation.canGoBack()) navigation.goBack();
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const ExportPrivateViewModal = () => {
onPress={copyDataToClipboard}
>
{intl.formatMessage({
id: 'action__copy_address',
id: 'action__copy',
})}
</Button>
</Box>
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/src/eventBus/appEventBus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const appEventBus = new CrossEventEmitter();

enum AppEventBusNames {
AccountNameChanged = 'AccountNameChanged',
NetworkChanged = 'NetworkChanged',
AccountChanged = 'AccountChanged',
}

export { appEventBus, AppEventBusNames };

0 comments on commit 93cd13c

Please sign in to comment.