Skip to content
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

CU-86a5jjanf - NEON3 - BUG - Send screen isn't enabling the send button #243

Merged
merged 1 commit into from
Nov 15, 2024
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
3 changes: 2 additions & 1 deletion src/renderer/src/components/TransactionFeeActionStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ export const TransactionFeeActionStep = ({ fee, isCalculatingFee, service }: TPr
) : (
<div className="flex items-center gap-4.5">
<span className="text-gray-100">
{fee} {service?.feeToken.symbol}
{fee ?? '0.00'} {service?.feeToken.symbol}
</span>

<span className="text-gray-300">{NumberHelper.currency(fiatFee, currency.label)}</span>
</div>
)}
Expand Down
63 changes: 35 additions & 28 deletions src/renderer/src/routes/pages/Send/SendPageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,27 @@ export const SendPageContent = ({ account, recipientAddress }: TProps) => {

for (const recipient of recipients) {
if (!recipient.token || !recipient.amount || !recipient.address) {
if (!recipient.amount) {
clearErrors('selectedAccount')
}

setError('recipients', '')
return
}

const amountNumber = NumberHelper.number(recipient.amount)
const tokenHash = UtilsHelper.normalizeHash(recipient.token!.token.hash)
const tokenBalance = balance.data?.tokensBalances.find(
tokenBalance => UtilsHelper.normalizeHash(tokenBalance.token.hash) === tokenHash
)

if (!tokenBalance || amountNumber > tokenBalance.amountNumber) {
setError('selectedAccount', t('errors.insufficientFunds'))
return
}
}

clearErrors('recipients')
clearErrors(['recipients', 'selectedAccount'])
}

const handleSelectAccount = (account?: IAccountState) => {
Expand Down Expand Up @@ -213,8 +228,14 @@ export const SendPageContent = ({ account, recipientAddress }: TProps) => {
useEffect(() => {
if (balance.isLoading) return

const abortController = new AbortController()

const handleCalculateFee = async () => {
try {
// It works as a debounce
await UtilsHelper.sleep(1000)
if (abortController.signal.aborted) return

const fields = await getSendFields()
if (!fields || !isCalculableFee(fields.service)) {
setData({ fee: undefined })
Expand All @@ -229,7 +250,7 @@ export const SendPageContent = ({ account, recipientAddress }: TProps) => {
})

setData({
fee: `${fee} ${fields.service.feeToken.symbol}`,
fee,
})

let totalFeeAmount = NumberHelper.number(fee)
Expand All @@ -255,40 +276,21 @@ export const SendPageContent = ({ account, recipientAddress }: TProps) => {
} catch (error) {
console.error(error)
ToastHelper.error({ message: t('errors.feeError') })
setError('fee', t('errors.feeError'))
setData({ fee: undefined })
throw error
} finally {
setData({ isCalculatingFee: false })
}
}

handleCalculateFee()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [actionData.recipients, balance.data])

useEffect(() => {
const validateAmounts = () => {
for (const recipient of actionData.recipients) {
if (!recipient.amount || !recipient.token) {
continue
}

const amountNumber = NumberHelper.number(recipient.amount)
const tokenHash = UtilsHelper.normalizeHash(recipient.token!.token.hash)
const tokenBalance = balance.data?.tokensBalances.find(
tokenBalance => UtilsHelper.normalizeHash(tokenBalance.token.hash) === tokenHash
)

if (!tokenBalance || amountNumber > tokenBalance.amountNumber) {
setError('recipients', t('errors.insufficientFunds'))
return
}
}

clearErrors('recipients')
return () => {
abortController.abort()
}

validateAmounts()
}, [actionData.recipients, balance.data?.tokensBalances, clearErrors, setError, t])
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [actionData.recipients, balance.data])

useEffect(() => {
handleSelectAccount(account)
Expand Down Expand Up @@ -359,7 +361,12 @@ export const SendPageContent = ({ account, recipientAddress }: TProps) => {
/>
)}

{actionState.errors.fee && <AlertErrorBanner className="w-full mt-2" message={actionState.errors.fee} />}
{(actionState.errors.fee || actionState.errors.selectedAccount) && (
<AlertErrorBanner
className="w-full mt-2"
message={actionState.errors.fee || actionState.errors.selectedAccount || ''}
/>
)}

<Button
className="max-w-[16rem] w-full mt-4"
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/routes/pages/Send/SendRecipient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export const SendRecipient = ({
leftIcon={<VscCircleFilled className="text-gray-300 w-2 h-2" />}
>
<GreyAmountInput
value={recipient.amount}
value={recipient.amount ?? ''}
onChange={handleChangeAmount}
disabled={!selectedAccount || !recipient.token}
/>
Expand Down