Skip to content

Commit 1d9b58c

Browse files
authored
Merge pull request #11188 from hassnian/issue-mm-0001
fix: massmint not checking balance when minting
2 parents 84aea3d + 2f214aa commit 1d9b58c

File tree

7 files changed

+23
-11
lines changed

7 files changed

+23
-11
lines changed

components/create/Confirm/MintConfirmModal.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import { CreateComponent } from '@/composables/useCreate'
5555
import { useFiatStore } from '@/stores/fiat'
5656
import { usePreferencesStore } from '@/stores/preferences'
5757
import { availablePrefixes } from '@/utils/chain'
58-
import { getTransitionFee } from '@/utils/transactionExecutor'
5958
import { calculateBalanceUsdValue } from '@/utils/format/balance'
6059
import { BASE_FEE } from '@/utils/support'
6160
import type { AutoTeleportAction } from '@/composables/autoTeleport/types'
@@ -183,7 +182,7 @@ const confirm = (params) => {
183182
watchEffect(async () => {
184183
networkFee.value = 0
185184
186-
const fee = await getTransitionFee(accountId.value, [''], decimals.value)
185+
const fee = await estimateTransactionFee(accountId.value, decimals.value)
187186
networkFee.value = props.nftInformation.listForSale
188187
? Number(fee) * 2
189188
: Number(fee)

components/create/CreateCollection.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ const submitButtonLabel = computed(() => {
288288
? $i18n.t('mint.nft.connect')
289289
: canDeposit.value
290290
? $i18n.t('mint.collection.create')
291-
: $i18n.t('confirmPurchase.notEnoughFuns')
291+
: $i18n.t('confirmPurchase.notEnoughFunds')
292292
})
293293
294294
const currentChain = computed(() => {

components/massmint/Massmint.vue

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@
5353
class="flex flex-grow limit-width"
5454
variant="primary"
5555
size="large"
56-
:disabled="!mediaLoaded"
56+
:disabled="!mediaLoaded || !hasEnoughBalance"
5757
@click="openReviewModal"
5858
>
59-
<span class="text-xl">{{ $t('massmint.mintNFTs') }}
59+
<span class="text-xl">{{ hasEnoughBalance ? $t('massmint.mintNFTs') : $t('confirmPurchase.notEnoughFunds') }}
6060
<span
61-
v-if="numOfValidNFTs"
61+
v-if="numOfValidNFTs && !hasEnoughBalance"
6262
class="font-bold"
6363
>
6464
({{ numOfValidNFTs }})
@@ -130,8 +130,11 @@ const preferencesStore = usePreferencesStore()
130130
const { $consola, $i18n } = useNuxtApp()
131131
const router = useRouter()
132132
const { urlPrefix } = usePrefix()
133-
const { selectedCollection, preselectedCollectionId, onCollectionSelected }
134-
= useCollectionDropdown()
133+
const { accountId } = useAuth()
134+
const { selectedCollection, preselectedCollectionId, onCollectionSelected } = useCollectionDropdown()
135+
const { itemDeposit, metadataDeposit } = useDeposit(urlPrefix)
136+
const { decimals } = useChain()
137+
const { transferableCurrentChainBalance } = useMultipleBalance(true)
135138
136139
const NFTS = ref<{ [nftId: string]: NFT }>({})
137140
const mediaLoaded = ref(false)
@@ -146,9 +149,13 @@ const mintModalOpen = ref(false)
146149
const MobileDisclaimerModalOpen = ref(false)
147150
const smallerThenDesktop = computed(() => width.value < 1024)
148151
152+
const transactionFee = ref(0)
149153
const isMinting = ref(false)
150154
const mintStatus = ref('')
151155
156+
const neededAmount = computed(() => ((itemDeposit.value + metadataDeposit.value) * Object.keys(NFTS.value).length) + transactionFee.value)
157+
const hasEnoughBalance = computed(() => (transferableCurrentChainBalance.value ?? 0) >= neededAmount.value)
158+
152159
const numberOfMissingNames = computed(
153160
() => Object.values(NFTS.value).filter(nft => !nft.name).length,
154161
)
@@ -275,6 +282,10 @@ const onDescriptionLoaded = (entries: Record<string, Entry>) => {
275282
onMounted(() => {
276283
MobileDisclaimerModalOpen.value = smallerThenDesktop.value
277284
})
285+
286+
watch(urlPrefix, async () => {
287+
transactionFee.value = Number(await estimateTransactionFee(accountId.value, decimals.value))
288+
}, { immediate: true })
278289
</script>
279290

280291
<style lang="scss" scoped>

composables/useMigrate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export function useMigrateDeposit(
158158

159159
const chainNetworkFee = computedAsync(async () => {
160160
if (account) {
161-
const fee = await getTransitionFee(account, [''], chainDecimals.value)
161+
const fee = await estimateTransactionFee(account, chainDecimals.value)
162162
return parseDeposit(
163163
parseInt(fee) * itemCount * itemCount,
164164
chainDecimals.value,

locales/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@
271271
"confirmPurchase": {
272272
"action": "Confirm Purchase",
273273
"connectedWith": "Connected as",
274-
"notEnoughFuns": "Not Enough Funds",
274+
"notEnoughFunds": "Not Enough Funds",
275275
"priceForNFTs": "Price for NFT(s)",
276276
"royalties": "Royalties",
277277
"youWillPay": "You Will Pay"

locales/hi.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@
199199
"confirmPurchase": {
200200
"action": "खरीदी की पुष्टि करें",
201201
"connectedWith": "के साथ कनेक्ट किया गया है",
202-
"notEnoughFuns": "पर्याप्त धन नहीं है",
202+
"notEnoughFunds": "पर्याप्त धन नहीं है",
203203
"priceForNFTs": "NFT(s) के लिए मूल्य",
204204
"royalties": "Royalty",
205205
"youWillPay": "आपको भुगतान करना होगा"

utils/transactionExecutor.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ export const getActionTransactionFee = ({
187187
})
188188
}
189189

190+
export const estimateTransactionFee = (account: string, decimals: number): Promise<string> => getTransitionFee(account, [''], decimals)
191+
190192
export const getTransitionFee = async (
191193
accountId: string,
192194
targetAddresses: Array<string>,

0 commit comments

Comments
 (0)