Skip to content

Commit

Permalink
fix: aptos handle existSDK window not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
q20274982 committed Jan 12, 2024
1 parent 48fa07a commit cba22a2
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions packages/blocto-sdk/src/providers/aptos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default class AptosProvider
sessionKey: KEY_SESSION;

private get existedSDK() {
if (typeof window === 'undefined') return undefined;
return (window as any).bloctoAptos;
}

Expand Down Expand Up @@ -147,7 +148,6 @@ export default class AptosProvider
transaction: AptosTypes.TransactionPayload,
txOptions: TxOptions = {}
): Promise<{ hash: AptosTypes.HexEncodedBytes }> {

if (this.existedSDK) {
return this.existedSDK.signAndSubmitTransaction(transaction, txOptions);
}
Expand Down Expand Up @@ -217,7 +217,6 @@ export default class AptosProvider
}

async signMessage(payload: SignMessagePayload): Promise<SignMessageResponse> {

const formattedPayload = checkMessagePayloadFormat(payload);

if (this.existedSDK) {
Expand Down Expand Up @@ -291,7 +290,10 @@ export default class AptosProvider
if (this.existedSDK) {
return new Promise((resolve, reject) =>
// add a small delay to make sure the network has been switched
setTimeout(() => this.existedSDK.connect().then(resolve).catch(reject), 10)
setTimeout(
() => this.existedSDK.connect().then(resolve).catch(reject),
10
)
);
}

Expand Down Expand Up @@ -406,18 +408,16 @@ export default class AptosProvider
}

override on(event: string, listener: (arg: any) => void): void {
if (this.existedSDK)
this.existedSDK.on(event, listener);

if (this.existedSDK) this.existedSDK.on(event, listener);

super.on(event, listener);
}

override removeListener(event: string, listener: (arg: any) => void): void {
if (this.existedSDK)
this.existedSDK.off(event, listener);

if (this.existedSDK) this.existedSDK.off(event, listener);

super.removeListener(event, listener);
}

off = this.removeListener;
}

0 comments on commit cba22a2

Please sign in to comment.