Skip to content

Commit

Permalink
added logic to ensure retry text ui logic works for both off and on c…
Browse files Browse the repository at this point in the history
…hain issuers
  • Loading branch information
Nick Taras authored and Nick Taras committed Oct 6, 2023
1 parent 0f00691 commit c44a795
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 36 deletions.
42 changes: 21 additions & 21 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 1 addition & 5 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
38 changes: 28 additions & 10 deletions src/client/views/select-issuers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export class SelectIssuers extends AbstractView {

this.client.registerUiUpdateCallback(UIUpdateEventType.ISSUERS_LOADED, () => {
this.ui.dismissLoader()
this.client.cancelTokenAutoload()
this.render()
})

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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

Expand All @@ -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
}

Expand All @@ -268,6 +285,7 @@ export class SelectIssuers extends AbstractView {
connectBtn.innerHTML = '<div class="lds-ellipsis lds-ellipsis-sm" style=""><div></div><div></div><div></div><div></div></div>'
connectBtn.style.display = 'block'
}

}

issuerConnected(issuer: string, tokens: any[], showTokens = true) {
Expand Down

0 comments on commit c44a795

Please sign in to comment.