Skip to content

Commit

Permalink
Merge pull request #878 from TokenScript/fix/re-direct-timers
Browse files Browse the repository at this point in the history
added event hooks for re-direct flow. For use with passive or active.
  • Loading branch information
nicktaras committed Oct 22, 2023
2 parents 08af158 + c0c91c5 commit 1b0bd0f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
17 changes: 9 additions & 8 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ export class Client {
private async loadRemoteOutletTokens(issuer: OffChainTokenConfig): Promise<OutletTokenResult | void> {
const redirectRequired = shouldUseRedirectMode(this.config.offChainRedirectMode)
if (redirectRequired) this.tokenStore.setTokens(issuer.collectionID, [])
if (this.ui) {
if (this.ui && !issuer.onChain) {
await waitForElementToExist('.load-container-tn')
this.ui.showLoader(
`<h4>${this.config.uiOptions?.reDirectIssuerEventHeading ?? 'Connecting to Issuers...'}</h4>`,
Expand All @@ -778,13 +778,12 @@ export class Client {
this.config.uiOptions?.cancelAction ?? 'Cancel'
}</button>`,
)
if (!issuer.onChain) {
this.enableTokenAutoLoadCancel()
await sleep(this.config.uiOptions.userCancelIssuerAutoRedirectTimer ?? 2500)
if (this.userCancelTokenAutoload) {
this.userCancelTokenAutoload = false
return {}
}
this.enableTokenAutoLoadCancel()
this.eventSender('page-redirecting', { collectionId: issuer.collectionID, tokenOrigin: issuer.tokenOrigin })
await sleep(this.config.uiOptions.userCancelIssuerAutoRedirectTimer ?? 2500)
if (this.userCancelTokenAutoload) {
this.userCancelTokenAutoload = false
return {}
}
}
const res = await this.messaging.sendMessage(
Expand Down Expand Up @@ -1009,6 +1008,7 @@ export class Client {
cancelAuthButton.onclick = () => {
const err = 'User cancelled authentication'
this.ui.showError(err)
this.eventSender('user-cancel', { eventType: 'authentication' })
this.eventSender('token-proof', { issuer, error: err, data: null })
}
})
Expand All @@ -1029,6 +1029,7 @@ export class Client {
document.querySelectorAll('.connect-btn-tn .lds-ellipsis').forEach((el) => {
el.parentElement.innerHTML = this.config.uiOptions?.loadAction ?? 'Load Collection'
})
this.eventSender('user-cancel', { eventType: 'page-redirect' })
}
})
.catch((err) => {
Expand Down
8 changes: 7 additions & 1 deletion src/client/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,21 @@ export interface TokenNegotiatorEventsArgs {
'opened-overlay': EventSenderOpenedOverlay
'closed-overlay': EventSenderClosedOverlay
loaded: EventSenderViewLoaded
'token-proof': any // EventSenderTokenProof // TODO: Update this
'token-proof': any
'connected-wallet': EventSenderConnectedWallet
'disconnected-wallet': EventSenderDisconnectedWallet
'tokens-selected': EventSenderTokensSelected
'tokens-loaded': EventSenderTokensLoaded
'network-change': string
'page-redirecting': PageRedirecting
'user-cancel': { eventType: string }
error: EventSenderError
}

export interface PageRedirecting {
collectionId: string
tokenOrigin: string
}
export interface EventSenderViewLoaded {
data: any
}
Expand Down

0 comments on commit 1b0bd0f

Please sign in to comment.