Skip to content

Commit

Permalink
added event hooks for re-direct flow. For use with passive or active.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Taras authored and Nick Taras committed Oct 22, 2023
1 parent 08af158 commit 0c4b894
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 0c4b894

Please sign in to comment.