Skip to content

Commit

Permalink
Set minimum amount that can be sent and prevent dust transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
mpwanyi256 committed Dec 21, 2022
1 parent 29ff76a commit 570195d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,6 @@
"ph": "Tagalog",
"cb": "Cebuano"
},
"noResults": "No results found"
"noResults": "No results found",
"minSendAmount": "Minimum amount that can be sent."
}
38 changes: 29 additions & 9 deletions src/views/Send/Send.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
:amount="amount"
:account="account"
:amount-fiat="amountFiat"
:minimum-send-amount="minimumAssetSendAmount"
@update:amount="(newAmount) => (amount = newAmount)"
@toggle-max="toggleMaxAmount"
@update:amountFiat="(amount) => (amountFiat = amount)"
@update:amountFiat="updateSendAmount"
:max="available"
:available="available"
:max-fiat="prettyFiatBalance(available, fiatRates[asset])"
Expand Down Expand Up @@ -128,7 +129,7 @@
class="btn btn-primary btn-lg"
id="send_review_button"
@click="review"
:disabled="!canSend"
:disabled="!canSend || !isValidSendAmount"
>
{{ $t('common.review') }}
</button>
Expand Down Expand Up @@ -323,7 +324,10 @@ export default {
memo: '',
updatingFees: false,
domainData: {},
domainResolver: null
domainResolver: null,
minimumAssetsSendAmounts: {
SOL: 0.0015
}
}
},
mounted() {
Expand All @@ -343,17 +347,20 @@ export default {
networkWalletBalances() {
return this.account?.balances
},
minimumAssetSendAmount() {
return this.minimumAssetsSendAmounts[this.asset] || 0
},
isValidSendAmount() {
return this.stateAmount >= this.minimumAssetSendAmount
},
amount: {
get() {
return this.stateAmount
},
set(newValue) {
if (newValue && !isNaN(newValue)) {
this.stateAmount = newValue
} else {
this.stateAmount = 0.0
}
this.stateAmountFiat = prettyFiatBalance(this.stateAmount, this.fiatRates[this.asset])
this.$nextTick(() => {
this.updateSendAmount(newValue)
})
}
},
amountFiat: {
Expand Down Expand Up @@ -524,6 +531,14 @@ export default {
getAssetIcon,
getAssetColorStyle,
shortenAddress,
updateSendAmount(newValue) {
if (newValue && !isNaN(newValue)) {
this.stateAmount = newValue
} else {
this.stateAmount = this.minimumAssetSendAmount
}
this.stateAmountFiat = prettyFiatBalance(this.stateAmount, this.fiatRates[this.asset])
},
async _updateSendFees(amount) {
const sendFees = await getSendTxFees(this.account.id, this.asset, amount, this.customFee)
if (amount === undefined) {
Expand Down Expand Up @@ -725,6 +740,11 @@ export default {
label: `${this.asset}`
}
})
// Set Asset minimum send Amount
this.$nextTick(() => {
this.stateAmount = this.minimumAssetSendAmount || 0.0
})
},
watch: {
selectedFee: {
Expand Down
18 changes: 16 additions & 2 deletions src/views/Send/SendInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,17 @@
<div class="send-bottom">
<div class="send-bottom-available" id="send_available_balance">
<span class="text-muted">{{ $t('common.available') }}</span>
{{ isNaN(available) ? '0' : dpUI(available) || '0' }} {{ asset }}
{{ isNaN(available) ? '0' : dpUI(available) || '0' }}<br />{{ asset }}
</div>
<v-popover v-if="minimumSendAmount && minimumSendAmount > 0" offset="1" trigger="hover focus">
<div class="send-bottom-available">
<span class="text-muted capitalised">{{ $t('common.minimum') }}</span>
{{ minimumSendAmount }}<br />{{ asset }}
</div>
<template slot="popover">
{{ $t('common.minSendAmount') }}
</template>
</v-popover>
<div class="send-bottom-options">
<div class="btn-group">
<v-popover offset="1" trigger="hover focus">
Expand Down Expand Up @@ -117,7 +126,8 @@ export default {
'available',
'maxFiat',
'amountError',
'maxActive'
'maxActive',
'minimumSendAmount'
],
computed: {
...mapState(['fiatRates'])
Expand Down Expand Up @@ -225,6 +235,10 @@ export default {
text-transform: none;
font-weight: $font-weight-light;
font-size: $font-size-tiny;
.capitalised {
text-transform: capitalize;
}
}
}
}
Expand Down

0 comments on commit 570195d

Please sign in to comment.