Skip to content

Commit

Permalink
Update OpenBit First Install Page problems
Browse files Browse the repository at this point in the history
  • Loading branch information
saltict committed May 23, 2024
1 parent 6f8f797 commit 1b943e3
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 21 deletions.
1 change: 1 addition & 0 deletions packages/extension-base/src/background/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export interface SigningRequest extends ConfirmationRequestBase {
// [MessageType]: [RequestType, ResponseType, SubscriptionMessageType?]
export interface RequestSignatures extends KoniRequestSignatures {
// private/internal requests, i.e. from a popup
'pri(ping)': [null, string];
'pri(accounts.create.external)': [RequestAccountCreateExternal, boolean];
'pri(accounts.create.hardware)': [RequestAccountCreateHardware, boolean];
'pri(accounts.create.suri)': [RequestAccountCreateSuri, boolean];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,6 @@ export default class KoniExtension {
const keyringService = this.#koniState.keyringService;
const transformedAccountProxies = transformAccountProxies(keyringService.accounts);

// @ts-ignore
const responseData: AccountProxiesWithCurrentProxy = {
accountProxies: transformedAccountProxies?.length ? [{ ...ACCOUNT_PROXY_ALL_JSON }, ...transformedAccountProxies] : [],
currentAccountProxyId: keyringService.currentAccountProxy?.proxyId
Expand Down Expand Up @@ -4921,6 +4920,8 @@ export default class KoniExtension {
}

switch (type) {
case 'pri(ping)':
return 'pong';
/// Clone from PolkadotJs
case 'pri(accounts.create.external)':
return this.accountsCreateExternal(request as RequestAccountCreateExternal);
Expand Down
10 changes: 8 additions & 2 deletions packages/extension-base/src/koni/background/handlers/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,11 @@ export default class KoniState {

private async onMV3Install () {
await SWStorage.instance.setItem('mv3_migration', 'done');

// Open expand page
const url = `${chrome.runtime.getURL('index.html')}#/welcome`;

withErrorLog(() => chrome.tabs.create({ url }));
}

public onInstallOrUpdate (details: chrome.runtime.InstalledDetails) {
Expand Down Expand Up @@ -1792,7 +1797,7 @@ export default class KoniState {
this.waitSleeping = null;
}

private async _start (isWakeup = false) {
private async _start () {
// Wait sleep finish before start to avoid conflict
this.generalStatus === ServiceStatus.STOPPING && this.waitSleeping && await this.waitSleeping;

Expand All @@ -1808,6 +1813,7 @@ export default class KoniState {
return;
}

const isWakeup = this.generalStatus === ServiceStatus.STOPPED;
const starting = createPromiseHandler<void>();

this.generalStatus = ServiceStatus.STARTING;
Expand All @@ -1829,7 +1835,7 @@ export default class KoniState {
}

public async wakeup () {
await this._start(true);
await this._start();
}

public cancelSubscription (id: string): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class SWHandler {
const isMobile = port.name === PORT_MOBILE;
const isExtension = port.name === PORT_EXTENSION;
const sender = port.sender;
// console.debug('Handle', message);

const from = isExtension
? 'extension'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export class EventService extends EventEmitter<EventRegistry> {
private generateWaitPromise<T extends EventType> (eventType: T): Promise<boolean> {
return new Promise((resolve) => {
this.once(eventType, (isReady) => {
console.log('===LOG generateWaitPromise eventType', eventType);
resolve(isReady);
});
});
Expand Down
3 changes: 3 additions & 0 deletions packages/extension-koni-ui/src/contexts/DataContext.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2019-2022 @subwallet/extension-koni-ui authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { ping } from '@subwallet/extension-koni-ui/messaging';
import { persistor, store, StoreName } from '@subwallet/extension-koni-ui/stores';
import { getLogoMaps, subscribeAccountProxiesData, subscribeAddressBook, subscribeAssetRegistry, subscribeAssetSettings, subscribeAuthorizeRequests, subscribeBalance, subscribeBitcoinConfirmationRequests, subscribeBuyServices, subscribeBuyTokens, subscribeChainInfoMap, subscribeChainStakingMetadata, subscribeChainStateMap, subscribeChainStatusMap, subscribeConfirmationRequests, subscribeConnectWCRequests, subscribeCrowdloan, subscribeKeyringState, subscribeMantaPayConfig, subscribeMantaPaySyncingState, subscribeMetadataRequests, subscribeMultiChainAssetMap, subscribeNftCollections, subscribeNftItems, subscribePrice, subscribeProcessingCampaign, subscribeSigningRequests, subscribeStaking, subscribeStakingNominatorMetadata, subscribeStakingReward, subscribeTransactionRequests, subscribeTxHistory, subscribeUiSettings, subscribeWalletConnectSessions, subscribeWCNotSupportRequests, subscribeXcmRefMap } from '@subwallet/extension-koni-ui/stores/utils';
import Bowser from 'bowser';
Expand Down Expand Up @@ -184,6 +185,8 @@ export function initBasicData () {
export const DataContext = React.createContext(_DataContext);

export const DataContextProvider = ({ children }: DataContextProviderProps) => {
ping().catch(console.error);

// Init basic data
initBasicData();

Expand Down
4 changes: 4 additions & 0 deletions packages/extension-koni-ui/src/messaging/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import { CronReloadRequest, Notification, RequestGetTransaction, RequestParseEvm
import { SWTransactionResult } from '@subwallet/extension-base/services/transaction-service/types';
import { sendMessage } from '@subwallet/extension-koni-ui/messaging/base';

export async function ping () {
return sendMessage('pri(ping)', null);
}

export async function windowOpen (params: WindowOpenParams): Promise<boolean> {
return sendMessage('pri(window.open)', params);
}
Expand Down
14 changes: 0 additions & 14 deletions packages/extension-koni/src/background-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,6 @@ chrome.runtime.onConnect.addListener((port): void => {
// Open expand page after install
chrome.runtime.onInstalled.addListener(function (details) {
actionHandler.onInstalled(details);

if (details.reason === 'install') {
// Add small timeout to avoid unwanted problems with the extension popup in the first time loaded
setTimeout(() => {
try {
// Open expand page
const url = `${chrome.runtime.getURL('index.html')}#/`;

withErrorLog(() => chrome.tabs.create({ url }));
} catch (e) {
console.error(e);
}
}, 900);
}
});

// Setup uninstall URL every background start
Expand Down
9 changes: 6 additions & 3 deletions packages/extension-koni/src/helper/ActionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,19 @@ export class ActionHandler {
}

public onInstalled (details: chrome.runtime.InstalledDetails): void {
this.waitMainHandler.promise.then((handler) => {
(async () => {
const handler = await this.waitMainHandler.promise;

handler.state.onInstallOrUpdate(details);
}).catch(console.error);
})().catch(console.error);
}

private _getPortId (port: chrome.runtime.Port): string {
return `${port.sender?.documentId || 'extension-popup'}`;
}

private async _onPortMessage (port: chrome.runtime.Port, data: TransportRequestMessage<keyof RequestSignatures>, portId: string) {
// console.debug(data.message, data.id, portId);
// message and disconnect handlers
if (!this.mainHandler) {
this.mainHandler = await this.waitMainHandler.promise;
Expand Down Expand Up @@ -81,7 +84,7 @@ export class ActionHandler {
}
}

this.mainHandler?.handle(data, port);
this.mainHandler.handle(data, port);
}

private _onPortDisconnect (port: chrome.runtime.Port, portId: string) {
Expand Down

1 comment on commit 1b943e3

@saltict
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.