Skip to content

Commit

Permalink
fix: better cancellation message
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Dec 30, 2024
1 parent a1cd839 commit 42b9b22
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class WalletPluginWebAuthenticator extends AbstractWalletPlugin implement
/**
* Opens a popup window with the given URL and waits for it to complete
*/
private async openPopup(url: string): Promise<any> {
private async openPopup(url: string, type: 'sign' | 'identity' = 'sign'): Promise<any> {
return new Promise((resolve, reject) => {
const popup = window.open(url, 'Web Authenticator', 'width=400,height=600')

Expand All @@ -75,7 +75,11 @@ export class WalletPluginWebAuthenticator extends AbstractWalletPlugin implement
const checkClosed = setInterval(() => {
if (popup.closed) {
clearInterval(checkClosed)
reject(new Error('Authentication cancelled'))
reject(
new Error(
type === 'sign' ? 'Transaction cancelled' : 'Authentication cancelled'
)
)
}
}, 1000)

Expand Down Expand Up @@ -106,7 +110,7 @@ export class WalletPluginWebAuthenticator extends AbstractWalletPlugin implement
const loginUrl = `${this.webAuthenticatorUrl}/sign?esr=${request.encode()}&chain=${
context.chain?.name
}`
const response = await this.openPopup(loginUrl)
const response = await this.openPopup(loginUrl, 'identity')

const {payload} = response

Expand Down Expand Up @@ -141,7 +145,7 @@ export class WalletPluginWebAuthenticator extends AbstractWalletPlugin implement
)}&chain=${context.chain?.name}&accountName=${context.accountName}&permissionName=${
context.permissionName
}`
const response = await this.openPopup(signUrl)
const response = await this.openPopup(signUrl, 'sign')

const wasSuccessful =
isCallback(response.payload) &&
Expand Down

0 comments on commit 42b9b22

Please sign in to comment.