Skip to content

Fix race condition in NFT studio #124 #125 #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 42 additions & 6 deletions src/components/wallet/studio/mint/MintForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@
<label>{{ $t('studio.mint.preview.success.label1') }}</label>
<p style="word-break: break-all">{{ txId }}</p>
</div>
<v-btn @click="clearUtxo" class="button_secondary" small depressed>
{{ $t('studio.mint.preview.success.back') }}
</v-btn>
<template v-if="canMintAgain">
<v-btn @click="clearUtxo" class="button_secondary" small depressed>
{{ $t('studio.mint.preview.success.back') }}
</v-btn>
</template>
</div>
</template>
</div>
Expand Down Expand Up @@ -171,6 +173,7 @@ export default class MintNft extends Vue {
canSubmit = false
isSuccess = false
isLoading = false
canMintAgain = false
txId = ''

maxPreviewUtxoLen = 18
Expand Down Expand Up @@ -322,19 +325,38 @@ 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)
}
}

cancel() {
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', {
Expand All @@ -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
}
Expand Down