Skip to content

Commit

Permalink
isConnected method in embedded wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
upalinski committed Dec 18, 2024
1 parent 90b5c79 commit db93ec9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/embed-wallet/src/EmbedWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,18 @@ export class EmbedWallet {
private proxyProvider: ProxyProvider;
private connectOptions: WalletConnectOptions = {};
private onAfterInit?: (error?: any) => void;
private onAfterConnect?: (error?: any) => void;

/**
* @description Promise that resolves when the wallet instance is initialized and ready
*/
readonly isReady: Promise<EmbedWallet>;

/**
* @description Promise that resolves when the wallet instance is connected
*/
readonly isConnected: Promise<EmbedWallet>;

constructor({ env, clientVersion = WALLET_CLIENT_VERSION, ...options }: WalletOptions = {}) {
if (env) {
preloadIframe(buildEnvMap[env], clientVersion);
Expand All @@ -91,7 +97,9 @@ export class EmbedWallet {
this.isReady = new Promise((resolve, reject) => {
this.onAfterInit = (error) => (error ? reject(error) : resolve(this));
});

this.isConnected = new Promise((resolve, reject) => {
this.onAfterConnect = (error) => (error ? reject(error) : resolve(this));
});
this.provider.on('message', this.handleEvenets);
}

Expand Down Expand Up @@ -215,11 +223,11 @@ export class EmbedWallet {
});

this.setStatus('connected');

this.onAfterConnect?.();
return address;
} catch (error) {
rollback();

this.onAfterConnect?.(error);
throw error;
}
}
Expand Down

0 comments on commit db93ec9

Please sign in to comment.