From 34050611b8c771ee67c07ff25ca6e9c7198a9d24 Mon Sep 17 00:00:00 2001 From: Owen Horwitz Date: Sat, 28 Aug 2021 19:35:52 -0700 Subject: [PATCH] Fix race condition in NFT studio #124 #125 --- .../wallet/studio/mint/MintForm.vue | 48 ++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/src/components/wallet/studio/mint/MintForm.vue b/src/components/wallet/studio/mint/MintForm.vue index 660b0438c..8c68dd0d5 100644 --- a/src/components/wallet/studio/mint/MintForm.vue +++ b/src/components/wallet/studio/mint/MintForm.vue @@ -112,9 +112,11 @@

{{ txId }}

- - {{ $t('studio.mint.preview.success.back') }} - + @@ -171,6 +173,7 @@ export default class MintNft extends Vue { canSubmit = false isSuccess = false isLoading = false + canMintAgain = false txId = '' maxPreviewUtxoLen = 18 @@ -322,9 +325,10 @@ export default class MintNft extends Vue { try { let txId = await wallet.mintNft(this.mintUtxo, this.payloadPreview, this.quantity) - this.onSuccess(txId) + this.waitTxConfirm(txId) } catch (e) { console.error(e) + this.onError(e) } } @@ -332,9 +336,27 @@ export default class MintNft extends Vue { this.$emit('cancel') } + async waitTxConfirm(txId: string) { + let status = await avm.getTxStatus(txId) + if (status === 'Unknown' || status === 'Processing') { + // if not confirmed ask again + setTimeout(() => { + this.waitTxConfirm(txId) + }, 500) + return + } else if (status === 'Dropped') { + // If dropped stop the process + this.isSuccess = false + return + } else { + // If success display success page + this.isSuccess = true + this.onSuccess(txId) + } + } + onSuccess(txId: string) { this.isLoading = false - this.isSuccess = true this.txId = txId this.$store.dispatch('Notifications/add', { @@ -343,12 +365,26 @@ export default class MintNft extends Vue { message: 'Collectible minted and added to your wallet.', }) + this.$store.dispatch('Assets/updateUTXOs').then(() => { + this.updateMintAgainLock() + }) + setTimeout(() => { - this.$store.dispatch('Assets/updateUTXOs') this.$store.dispatch('History/updateTransactionHistory') }, 2000) } + updateMintAgainLock() { + let wallet = this.$store.state.activeWallet + if (wallet && !wallet.isFetchUtxos) { + this.canMintAgain = true + } else { + setTimeout(() => { + this.updateMintAgainLock() + }, 1000) + } + } + onError(err: any) { this.isLoading = false }