From 0c4b894d62c582944e94433873b69496c79720df Mon Sep 17 00:00:00 2001 From: Nick Taras Date: Mon, 23 Oct 2023 10:28:52 +1100 Subject: [PATCH 1/2] added event hooks for re-direct flow. For use with passive or active. --- src/client/index.ts | 17 +++++++++-------- src/client/interface.ts | 8 +++++++- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/client/index.ts b/src/client/index.ts index 7afb56e3..052cfadc 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -769,7 +769,7 @@ export class Client { private async loadRemoteOutletTokens(issuer: OffChainTokenConfig): Promise { 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( `

${this.config.uiOptions?.reDirectIssuerEventHeading ?? 'Connecting to Issuers...'}

`, @@ -778,13 +778,12 @@ export class Client { this.config.uiOptions?.cancelAction ?? 'Cancel' }`, ) - 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( @@ -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 }) } }) @@ -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) => { diff --git a/src/client/interface.ts b/src/client/interface.ts index 3abf8f70..db6dd224 100644 --- a/src/client/interface.ts +++ b/src/client/interface.ts @@ -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 } From c0c91c51c63ff72f35f6a5da0ba925e1c4052cde Mon Sep 17 00:00:00 2001 From: Nick Taras Date: Mon, 23 Oct 2023 10:33:06 +1100 Subject: [PATCH 2/2] added event hooks for re-direct flow. For use with passive or active. --- src/client/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/index.ts b/src/client/index.ts index 052cfadc..3e1aa689 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -1008,7 +1008,7 @@ export class Client { cancelAuthButton.onclick = () => { const err = 'User cancelled authentication' this.ui.showError(err) - this.eventSender('user-cancel', { eventType: 'Authentication' }) + this.eventSender('user-cancel', { eventType: 'authentication' }) this.eventSender('token-proof', { issuer, error: err, data: null }) } })