diff --git a/src/app/actions/claimLinks.ts b/src/app/actions/claimLinks.ts index 71e48536c..cc93825ee 100644 --- a/src/app/actions/claimLinks.ts +++ b/src/app/actions/claimLinks.ts @@ -86,7 +86,8 @@ export async function getNextDepositIndex(contractVersion: string): Promise { const response = await fetchWithSentry(`${PEANUT_API_URL}/send-links/${pubKey}/claim`, { method: 'POST', @@ -97,6 +98,7 @@ export async function claimSendLink( body: JSON.stringify({ recipient, password, + waitForTx, }), }) if (!response.ok) { diff --git a/src/app/actions/history.ts b/src/app/actions/history.ts index afecc4b2f..0735e84b8 100644 --- a/src/app/actions/history.ts +++ b/src/app/actions/history.ts @@ -37,6 +37,6 @@ export async function getHistoryEntry(entryId: string, entryType: EHistoryEntryT } const data = await response.json() - const entry = completeHistoryEntry(data) + const entry = await completeHistoryEntry(data) return entry } diff --git a/src/components/Claim/Link/views/MantecaDetailsStep.view.tsx b/src/components/Claim/Link/views/MantecaDetailsStep.view.tsx index d7be3f0ff..5233cb391 100644 --- a/src/components/Claim/Link/views/MantecaDetailsStep.view.tsx +++ b/src/components/Claim/Link/views/MantecaDetailsStep.view.tsx @@ -1,10 +1,13 @@ 'use client' import { Button } from '@/components/0_Bruddle' -import BaseInput from '@/components/0_Bruddle/BaseInput' import { Icon } from '@/components/Global/Icons/Icon' import { MercadoPagoStep } from '@/types/manteca.types' -import { Dispatch, FC, SetStateAction } from 'react' +import { Dispatch, FC, SetStateAction, useState } from 'react' +import { MANTECA_COUNTRIES_CONFIG } from '@/constants' +import ValidatedInput from '@/components/Global/ValidatedInput' +import { validateCbuCvuAlias } from '@/utils/withdraw.utils' +import ErrorAlert from '@/components/Global/ErrorAlert' interface MantecaDetailsStepProps { setCurrentStep: Dispatch> @@ -20,22 +23,53 @@ const MantecaDetailsStep: FC = ({ const handleOnClick = async () => { setCurrentStep(MercadoPagoStep.REVIEW) } + const [errorMessage, setErrorMessage] = useState(null) + const [isDestinationAddressValid, setIsDestinationAddressValid] = useState(false) + const [isDestinationAddressChanging, setIsDestinationAddressChanging] = useState(false) + + const countryConfig = MANTECA_COUNTRIES_CONFIG['AR'] + + const validateDestinationAddress = async (value: string) => { + value = value.trim() + if (!value) { + return false + } + const { valid, message } = validateCbuCvuAlias(value) + if (!valid) { + setErrorMessage(message!) + } + return valid + } return ( <>

Enter account details

- setDestinationAddress(e.target.value)} - placeholder="CVU or Alias" + onUpdate={(update) => { + setDestinationAddress(update.value) + setIsDestinationAddressValid(update.isValid) + setIsDestinationAddressChanging(update.isChanging) + if (update.isValid || update.value === '') { + setErrorMessage(null) + } + }} + placeholder={countryConfig.accountNumberLabel} + validate={validateDestinationAddress} />
You can only withdraw to accounts under your name.
- - diff --git a/src/components/Claim/Link/views/MantecaReviewStep.tsx b/src/components/Claim/Link/views/MantecaReviewStep.tsx index fe1c882a0..fb24a2897 100644 --- a/src/components/Claim/Link/views/MantecaReviewStep.tsx +++ b/src/components/Claim/Link/views/MantecaReviewStep.tsx @@ -30,8 +30,8 @@ const MantecaReviewStep: FC = ({ const detailsCardRows: MantecaCardRow[] = [ { - key: 'alias', - label: 'Alias', + key: 'destinationAddress', + label: 'Destination Address', value: destinationAddress, allowCopy: true, }, @@ -52,8 +52,9 @@ const MantecaReviewStep: FC = ({ try { setError(null) setIsSubmitting(true) - const claimResponse = await sendLinksApi.claim(MANTECA_DEPOSIT_ADDRESS, claimLink) - const txHash = claimResponse?.claim?.txHash + const waitForTx = true + const claimResponse = await sendLinksApi.claim(MANTECA_DEPOSIT_ADDRESS, claimLink, waitForTx) + const txHash = claimResponse.claim?.txHash if (!txHash) { setError('Claim failed: missing transaction hash.') return diff --git a/src/components/TransactionDetails/TransactionCard.tsx b/src/components/TransactionDetails/TransactionCard.tsx index d9665c06d..131283134 100644 --- a/src/components/TransactionDetails/TransactionCard.tsx +++ b/src/components/TransactionDetails/TransactionCard.tsx @@ -89,9 +89,9 @@ const TransactionCard: React.FC = ({ const displayAmount = `${sign}$${formattedAmount}` let currencyDisplayAmount: string | undefined - if (transaction.currency && transaction.currency.code !== 'USD') { + if (transaction.currency && transaction.currency.code.toUpperCase() !== 'USD') { const formattedCurrencyAmount = formatNumberForDisplay(transaction.currency.amount, { maxDecimals: 2 }) - currencyDisplayAmount = `≈ ${transaction.currency.code} ${formattedCurrencyAmount}` + currencyDisplayAmount = `≈ ${transaction.currency.code.toUpperCase()} ${formattedCurrencyAmount}` } return ( diff --git a/src/services/sendLinks.ts b/src/services/sendLinks.ts index 5226cd26d..df2980c4b 100644 --- a/src/services/sendLinks.ts +++ b/src/services/sendLinks.ts @@ -149,10 +149,10 @@ export const sendLinksApi = { * @param destinationAddress - The destination address to claim the link to (for manteca claims) * @returns The claim link data */ - claim: async (recipient: string, link: string): Promise => { + claim: async (recipient: string, link: string, waitForTx: boolean = false): Promise => { const params = getParamsFromLink(link) const pubKey = generateKeysFromString(params.password).address - const response = await claimSendLink(pubKey, recipient, params.password) + const response = await claimSendLink(pubKey, recipient, params.password, waitForTx) if ('error' in response) { throw new Error(response.error) } diff --git a/src/utils/history.utils.ts b/src/utils/history.utils.ts index 5ee7da003..fc813eb13 100644 --- a/src/utils/history.utils.ts +++ b/src/utils/history.utils.ts @@ -5,6 +5,7 @@ import { PEANUT_WALLET_TOKEN_DECIMALS, BASE_URL } from '@/constants' import { formatUnits } from 'viem' import { Hash } from 'viem' import { getTokenDetails } from '@/utils' +import { getCurrencyPrice } from '@/app/actions/currency' export enum EHistoryEntryType { REQUEST = 'REQUEST', @@ -19,6 +20,7 @@ export enum EHistoryEntryType { MANTECA_QR_PAYMENT = 'MANTECA_QR_PAYMENT', MANTECA_OFFRAMP = 'MANTECA_OFFRAMP', MANTECA_ONRAMP = 'MANTECA_ONRAMP', + BRIDGE_GUEST_OFFRAMP = 'BRIDGE_GUEST_OFFRAMP', } export function historyTypeToNumber(type: EHistoryEntryType): number { return Object.values(EHistoryEntryType).indexOf(type) @@ -183,7 +185,7 @@ export function getTransactionSign(transaction: Pick { const extraData = entry.extraData ?? {} let link: string = '' let tokenSymbol: string = '' @@ -230,12 +232,30 @@ export function completeHistoryEntry(entry: HistoryEntry): HistoryEntry { } break } - case EHistoryEntryType.WITHDRAW: + case EHistoryEntryType.BRIDGE_ONRAMP: { + tokenSymbol = entry.tokenSymbol + usdAmount = entry.amount.toString() + if (entry.currency?.code) { + entry.currency.code = entry.currency.code.toUpperCase() + } + if (usdAmount === entry.currency?.amount && entry.currency?.code && entry.currency?.code !== 'USD') { + const price = await getCurrencyPrice(entry.currency.code) + usdAmount = (Number(entry.currency.amount) * price.sell).toString() + } + break + } case EHistoryEntryType.BRIDGE_OFFRAMP: - case EHistoryEntryType.BRIDGE_ONRAMP: + case EHistoryEntryType.BRIDGE_GUEST_OFFRAMP: case EHistoryEntryType.BANK_SEND_LINK_CLAIM: { tokenSymbol = entry.tokenSymbol - usdAmount = entry.amount.toString() + usdAmount = entry.amount + if (entry.currency?.code) { + entry.currency.code = entry.currency.code.toUpperCase() + } + if (usdAmount === entry.currency?.amount && entry.currency?.code && entry.currency?.code !== 'USD') { + const price = await getCurrencyPrice(entry.currency.code) + entry.currency.amount = (Number(entry.amount) * price.buy).toString() + } break } default: {