9393 :fee =" gasCostValues[selectedFee]"
9494 />
9595
96- <send-alert
97- v-show =" hasEnoughBalance && nativeBalanceAfterTransaction.isNeg()"
98- :native-symbol =" network.currencyName"
99- :price =" accountAssets[0]?.price || '0'"
100- :native-value ="
101- fromBase(
102- nativeBalanceAfterTransaction.abs().toString(),
103- network.decimals,
104- )
105- "
106- :decimals =" network.decimals"
107- />
96+ <send-alert v-show =" errorMsg" :error-msg =" errorMsg" />
10897
10998 <div class =" send-transaction__buttons" >
11099 <div class =" send-transaction__buttons-cancel" >
@@ -133,7 +122,7 @@ import SendContactsList from '@/providers/common/ui/send-transaction/send-contac
133122import AssetsSelectList from ' @action/views/assets-select-list/index.vue' ;
134123import NftSelectList from ' @/providers/common/ui/send-transaction/nft-select-list/index.vue' ;
135124import SendTokenSelect from ' ./components/send-token-select.vue' ;
136- import SendAlert from ' @/providers/common/ui/send-transaction /send-alert.vue' ;
125+ import SendAlert from ' ./components /send-alert.vue' ;
137126import SendNftSelect from ' @/providers/common/ui/send-transaction/send-nft-select.vue' ;
138127import SendInputAmount from ' @/providers/common/ui/send-transaction/send-input-amount.vue' ;
139128import SendFeeSelect from ' ./components/send-fee-select.vue' ;
@@ -148,7 +137,10 @@ import BigNumber from 'bignumber.js';
148137import { defaultGasCostVals } from ' @/providers/common/libs/default-vals' ;
149138import { fromBase , toBase , isValidDecimals } from ' @enkryptcom/utils' ;
150139import { VerifyTransactionParams , SendTransactionDataType } from ' ../types' ;
151- import { formatFloatingPointValue } from ' @/libs/utils/number-formatter' ;
140+ import {
141+ formatFloatingPointValue ,
142+ formatFiatValue ,
143+ } from ' @/libs/utils/number-formatter' ;
152144import { routes as RouterNames } from ' @/ui/action/router' ;
153145import getUiPath from ' @/libs/utils/get-ui-path' ;
154146import Browser from ' webextension-polyfill' ;
@@ -328,6 +320,50 @@ const nativeBalanceAfterTransaction = computed(() => {
328320 return toBN (0 );
329321});
330322
323+ const nativeValue = computed (() => {
324+ return fromBase (
325+ nativeBalanceAfterTransaction .value .toString (),
326+ props .network .decimals ,
327+ );
328+ });
329+
330+ const nativePrice = computed (() => {
331+ return accountAssets .value [0 ]?.price || ' 0' ;
332+ });
333+
334+ const priceDifference = computed (() => {
335+ return new BigNumber (nativeValue .value )
336+ .times (nativePrice .value ?? ' 0' )
337+ .toFixed ();
338+ });
339+
340+ const errorMsg = computed (() => {
341+ if (hasEnoughBalance .value && nativeBalanceAfterTransaction .value .isNeg ()) {
342+ return ` Not enough funds. You are
343+ ~${formatFloatingPointValue (nativeValue .value ).value }
344+ ${props .network .currencyName } ($ ${
345+ formatFiatValue (priceDifference .value ).value
346+ }) short. ` ;
347+ }
348+ if (
349+ ! props .network .isAddress (getAddress (addressTo .value )) &&
350+ addressTo .value !== ' '
351+ )
352+ return ` Invalid to address. ` ;
353+ if (
354+ isSendToken .value &&
355+ ! isValidDecimals (sendAmount .value , selectedAsset .value .decimals ! )
356+ ) {
357+ return ` Invalid decimals for ${selectedAsset .value .symbol }. ` ;
358+ }
359+ if (! isSendToken .value && ! selectedNft .value .id ) {
360+ return ` Invalid NFT selected. ` ;
361+ }
362+ if (new BigNumber (sendAmount .value ).gt (assetMaxValue .value ))
363+ return ` Amount exceeds maximum value. ` ;
364+ return ' ' ;
365+ });
366+
331367const setTransactionFees = (tx : SolTransaction ) => {
332368 return tx
333369 .getEstimatedFee (solConnection .value ! .web3 )
@@ -421,13 +457,28 @@ const updateTransactionFees = async () => {
421457 }),
422458 );
423459 if (isSendToken .value && TxInfo .value .contract === NATIVE_TOKEN_ADDRESS ) {
460+ const toBalance = await solConnection .value ! .web3 .getBalance (to );
461+ const rentExempt =
462+ await solConnection .value ! .web3 .getMinimumBalanceForRentExemption (
463+ ACCOUNT_SIZE ,
464+ );
424465 transaction .add (
425466 SystemProgram .transfer ({
426467 fromPubkey: from ,
427468 toPubkey: to ,
428469 lamports: toBN (TxInfo .value .value ).toNumber (),
429470 }),
430471 );
472+ if (toBN (toBalance ).lt (toBN (rentExempt ))) {
473+ storageFee .value = rentExempt - toBalance ;
474+ transaction .add (
475+ SystemProgram .transfer ({
476+ fromPubkey: from ,
477+ toPubkey: to ,
478+ lamports: storageFee .value ,
479+ }),
480+ );
481+ }
431482 } else if (
432483 isSendToken .value ||
433484 (! isSendToken .value && selectedNft .value .type === NFTType .SolanaToken )
0 commit comments