From c44a795fb298ddd280e21e1ca55dd79869d4f079 Mon Sep 17 00:00:00 2001 From: Nick Taras Date: Fri, 6 Oct 2023 12:40:13 +1100 Subject: [PATCH] added logic to ensure retry text ui logic works for both off and on chain issuers --- index.html | 42 +++++++++++++++--------------- src/client/index.ts | 6 +---- src/client/views/select-issuers.ts | 38 ++++++++++++++++++++------- 3 files changed, 50 insertions(+), 36 deletions(-) diff --git a/index.html b/index.html index b3a6d934..e7f29069 100644 --- a/index.html +++ b/index.html @@ -283,27 +283,27 @@ // // Add fungible as a boolean // // symbol: 'USX' // }, - // { - // contract: "0x107065a122f92636a1358a70a0efe0f1a080a7e5", - // onChain: true, - // fungible: true, - // collectionID: "USX", - // chain: "matic", - // }, - // { - // contract: "0x429f49faec3d568ef83ec803e02df78e25d5ee7d", - // onChain: true, - // fungible: true, - // collectionID: "Ella", - // chain: "matic", - // }, - // { - // contract: "0xaaa5b9e6c589642f98a1cda99b9d024b8407285a", - // onChain: true, - // fungible: true, - // collectionID: "TITAN", - // chain: "matic", - // }, + { + contract: "0x107065a122f92636a1358a70a0efe0f1a080a7e5", + onChain: true, + fungible: true, + collectionID: "USX", + chain: "matic", + }, + { + contract: "0x429f49faec3d568ef83ec803e02df78e25d5ee7d", + onChain: true, + fungible: true, + collectionID: "Ella", + chain: "matic", + }, + { + contract: "0xaaa5b9e6c589642f98a1cda99b9d024b8407285a", + onChain: true, + fungible: true, + collectionID: "TITAN", + chain: "matic", + }, ], uiOptions: { openingHeading: diff --git a/src/client/index.ts b/src/client/index.ts index 00faa505..3aa475f8 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -136,6 +136,7 @@ export class Client { this.config = this.mergeConfig(defaultConfig, config) + // TODO investigate if this works correctly. this.config.autoLoadTokens = localStorage.getItem('tn-autoload-tokens') === 'false' ? false : this.config.autoLoadTokens this.tokenStore = new TokenStore(this.config.autoEnableTokens, this.config.tokenPersistenceTTL) @@ -674,11 +675,6 @@ export class Client { this.eventSender('tokens-selected', { selectedTokens: tokens }) this.eventSender('tokens-loaded', { loadedCollections: Object.keys(tokens).length }) - // use retry logic here too - // document.querySelectorAll('.connect-btn-tn .lds-ellipsis').forEach((el) => { - // el.parentElement.innerHTML = this.config.uiOptions?.loadAction ?? 'Load Collection' - // }) - // Feature not supported when an end users third party cookies are disabled // because the use of a tab requires a user gesture. if (this.messaging.core.iframeStorageSupport === false && Object.keys(this.tokenStore.getCurrentTokens(false)).length === 0) diff --git a/src/client/views/select-issuers.ts b/src/client/views/select-issuers.ts index 671f7a92..8f8b8636 100644 --- a/src/client/views/select-issuers.ts +++ b/src/client/views/select-issuers.ts @@ -17,7 +17,6 @@ export class SelectIssuers extends AbstractView { this.client.registerUiUpdateCallback(UIUpdateEventType.ISSUERS_LOADED, () => { this.ui.dismissLoader() - this.client.cancelTokenAutoload() this.render() }) @@ -160,6 +159,7 @@ export class SelectIssuers extends AbstractView { } this.issuerListContainer.addEventListener('click', (e: any) => { + console.log('yolo', e.target.dataset.issuer); if (e.target.classList.contains('connect-btn-tn')) { this.connectTokenIssuer(e) this.client.getTokenStore().setIncrementCollectionLoadAttempts(e.target.dataset.issuer); @@ -216,16 +216,35 @@ export class SelectIssuers extends AbstractView { async autoLoadTokens(refresh = false) { await this.client.tokenAutoLoad( this.issuerLoading.bind(this), - (issuer: string, tokens: any[]) => { - if (!tokens?.length) { - return - } - this.issuerConnected(issuer, tokens, false) - }, + this.issuerLoadingComplete.bind(this), refresh, ) } + issuerLoadingComplete(issuer: string, tokens: any[]) { + if (!tokens?.length) { + this.issuerDidntConnect(issuer); + } else { + this.issuerConnected(issuer, tokens, false) + } + } + + issuerDidntConnect(issuer: string, showNotification = false) { + const collectLoadAttempts = this.client.getTokenStore().getCollectionLoadAttempts(issuer); + let issuerButtonText = this.params.options?.loadAction ?? "Load Collection"; + if (collectLoadAttempts >= 1) issuerButtonText = this.params.options?.repeatAction ?? 'Retry'; + const connectBtn = this.issuerListContainer.querySelector(`[data-issuer="${issuer}"] .connect-btn-tn`) + if (connectBtn) { + connectBtn.innerHTML = issuerButtonText; + connectBtn.style.display = 'block' + } + if (showNotification) { + this.ui.showError(` + ${this.params.options.noTokensFoundEvent ?? 'No tokens found! '} + ${this.client.getNoTokenMsg(issuer)}`) + } + } + async connectTokenIssuer(event: any) { const data = event.target.dataset @@ -248,9 +267,7 @@ export class SelectIssuers extends AbstractView { this.ui.dismissLoader() if (!tokens?.length) { - this.ui.showError(` - ${this.params.options.noTokensFoundEvent ?? 'No tokens found! '} - ${this.client.getNoTokenMsg(issuer)}`) + this.issuerDidntConnect(issuer, true); return } @@ -268,6 +285,7 @@ export class SelectIssuers extends AbstractView { connectBtn.innerHTML = '
' connectBtn.style.display = 'block' } + } issuerConnected(issuer: string, tokens: any[], showTokens = true) {