Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,11 @@ const feeFiatValue = computed(() => {

const sendAmount = computed(() => {
if (amount.value && amount.value !== '') return amount.value;
return '0';
return '';
});

const hasEnoughBalance = computed(() => {
if (!isInputsValid.value || !selectedAsset.value) {
if (!selectedAsset.value || !sendAmount.value || sendAmount.value === '') {
return true;
}

Expand Down Expand Up @@ -266,19 +266,25 @@ const sendButtonTitle = computed(() => {

const hasValidDecimals = computed((): boolean => {
if (!selectedAsset.value) return false;
if (sendAmount.value === '') return true; // Empty amount is valid
return isValidDecimals(sendAmount.value, selectedAsset.value.decimals);
});

const hasPositiveSendAmount = computed(() => {
return isNumericPositive(sendAmount.value);
return sendAmount.value !== '' && isNumericPositive(sendAmount.value);
});

const errorMsg = computed(() => {
if (!hasValidDecimals.value) {
// Only show decimal validation errors if an asset is selected
if (selectedAsset.value && !hasValidDecimals.value) {
return `Too many decimals.`;
}

if (!hasPositiveSendAmount.value) {
if (
!hasPositiveSendAmount.value &&
sendAmount.value !== '0' &&
sendAmount.value !== ''
) {
return `Invalid amount.`;
}

Expand Down Expand Up @@ -313,19 +319,24 @@ const isInputsValid = computed<boolean>(() => {
return false;
}

// Check if amount is provided and not empty
if (!sendAmount.value || sendAmount.value.trim() === '') {
return false;
}

// Check if amount has valid decimals for the selected token
if (!hasValidDecimals.value) {
return false;
}

// Check if amount is a valid number
const amountNum = parseFloat(sendAmount.value);
if (isNaN(amountNum)) {
// Check if amount is a valid positive number
if (!hasPositiveSendAmount.value) {
return false;
}

// Check if amount is greater than 0
if (amountNum <= 0) {
// Check if amount is greater than 0 using BigNumber for precision
const amountBN = new BigNumber(sendAmount.value);
if (amountBN.lte(0)) {
return false;
}

Expand Down Expand Up @@ -452,10 +463,17 @@ const selectAccountFrom = (account: string) => {

const inputAmount = (inputAmount: string) => {
if (inputAmount === '') {
inputAmount = '0';
amount.value = '';
return;
}
const inputAmountBn = new BigNumber(inputAmount);
amount.value = inputAmountBn.lt(0) ? '0' : inputAmount;
if (inputAmountBn.isNaN()) {
// Keep the current valid amount if input is invalid
return;
}

// Only allow positive amounts or empty string
amount.value = inputAmountBn.lt(0) ? '' : inputAmount;
};

const setMaxValue = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,21 +275,12 @@ const sendAction = async () => {
});
}

if (getCurrentContext() === 'popup') {
setTimeout(() => {
showOperationId.value = false;
isProcessing.value = false;
callToggleRate();
router.push({ name: 'activity', params: { id: network.value.name } });
}, 4000);
} else {
setTimeout(() => {
showOperationId.value = false;
isProcessing.value = false;
callToggleRate();
window.close();
}, 3000);
}
setTimeout(() => {
showOperationId.value = false;
isProcessing.value = false;
callToggleRate();
router.push({ name: 'activity', params: { id: network.value.name } });
}, 4000);
} catch (error) {
isProcessing.value = false;
errorMsg.value = (error as any).error
Expand Down
20 changes: 16 additions & 4 deletions packages/extension/src/ui/action/views/network-activity/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -222,12 +222,24 @@ const handleActivityUpdate = (activity: Activity, info: any, timer: any) => {
} else if (props.network.provider === ProviderName.massa) {
if (!info) return;
const massaInfo = info as MassaRawInfo;
if (isActivityUpdating) return;
activity.status =
if (isActivityUpdating || massaInfo === OperationStatus.PendingInclusion)
return;

let status = ActivityStatus.failed;
// if the transaction is not found, and it's been less than 1 minute, wait for it to be processed
if (
massaInfo === OperationStatus.NotFound &&
Date.now() < activity.timestamp + 60_000
) {
return;
} else if (
massaInfo === OperationStatus.Success ||
massaInfo === OperationStatus.SpeculativeSuccess
? ActivityStatus.success
: ActivityStatus.failed;
) {
status = ActivityStatus.success;
}

activity.status = status;
activity.rawInfo = massaInfo;
updateActivitySync(activity).then(() => updateVisibleActivity(activity));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ import { formatFloatingPointValue } from '@/libs/utils/number-formatter';
import Tooltip from '@/ui/action/components/tooltip/index.vue';
import BigNumber from 'bignumber.js';
import { BaseNetwork } from '@/types/base-network';
import { Address, MRC20 } from '@massalabs/massa-web3';
import { MRC20 } from '@massalabs/massa-web3';
import MassaAPI from '../../../../../providers/massa/libs/api';
import { MassaNetwork } from '../../../../../providers/massa/networks/massa-base';

interface IProps {
network: BaseNetwork;
Expand All @@ -135,12 +136,9 @@ const isFocus = ref(false);

const isValidAddress = computed(() => {
if (contractAddress.value) {
try {
Address.fromString(contractAddress.value);
return true;
} catch (error) {
return false;
}
return (props.network as MassaNetwork).isValidAddress(
contractAddress.value,
);
}
return false;
});
Expand Down Expand Up @@ -188,7 +186,7 @@ const fetchTokenInfo = async () => {
contractAddress.value,
);
accountBalance.value = balance;
} catch (balanceError) {
} catch (_error) {
accountBalance.value = '0';
}

Expand All @@ -206,7 +204,7 @@ const addToken = async () => {

try {
// Add token to state
await tokensState.addMassaToken(props.network.name, toRaw(tokenInfo.value));
await tokensState.addErc20Token(props.network.name, toRaw(tokenInfo.value));

// Create asset for UI
const balanceFormatted = fromBase(
Expand Down
Loading