-
Notifications
You must be signed in to change notification settings - Fork 13
[TASK-12885]Feat/manteca add flow #1187
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d1ca804
setup component structure
Zishan-7 9461aae
integrate deposit API
Zishan-7 7ae1406
Complete API integration and add Brazil support (disabled)
Zishan-7 13662ab
generate share button text
Zishan-7 58f66f3
comment unused code
Zishan-7 bfe4da5
fix: build error
Zishan-7 3de2c83
Merge remote-tracking branch 'origin/feat/manteca-integration' into f…
Zishan-7 21cc0f9
Remove brazil flow
Zishan-7 39742c8
fix: improve error handling in MercadoPago component
Zishan-7 de63db6
use iso2 code for flag
Zishan-7 ea8bccf
fix: update button disabled state in InputAmountStep and add type for…
Zishan-7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
src/app/(mobile-ui)/add-money/[country]/[regional-method]/page.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| 'use client' | ||
| import MercadoPago from '@/components/AddMoney/components/RegionalMethods/MercadoPago' | ||
| import { useParams } from 'next/navigation' | ||
|
|
||
| export default function AddMoneyRegionalMethodPage() { | ||
| const params = useParams() | ||
| const country = params.country as string | ||
| const method = params['regional-method'] as string | ||
|
|
||
| if (country === 'argentina' && method === 'mercadopago') { | ||
| return <MercadoPago source="regionalMethod" /> | ||
| } | ||
|
|
||
| return <div>Unsupported Method</div> | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| 'use client' | ||
|
|
||
| import { Button } from '@/components/0_Bruddle' | ||
| import { Icon } from '@/components/Global/Icons/Icon' | ||
| import NavHeader from '@/components/Global/NavHeader' | ||
| import TokenAmountInput from '@/components/Global/TokenAmountInput' | ||
| import { useRouter } from 'next/navigation' | ||
| import { CountryData } from '../consts' | ||
| import ErrorAlert from '@/components/Global/ErrorAlert' | ||
| import { useCurrency } from '@/hooks/useCurrency' | ||
| import PeanutLoading from '@/components/Global/PeanutLoading' | ||
|
|
||
| interface InputAmountStepProps { | ||
| onSubmit: () => void | ||
| selectedCountry: CountryData | ||
| isLoading: boolean | ||
| tokenAmount: string | ||
| setTokenAmount: React.Dispatch<React.SetStateAction<string>> | ||
| setTokenUSDAmount: React.Dispatch<React.SetStateAction<string>> | ||
| error: string | null | ||
| } | ||
|
|
||
| const InputAmountStep = ({ | ||
| tokenAmount, | ||
| setTokenAmount, | ||
| onSubmit, | ||
| selectedCountry, | ||
| isLoading, | ||
| error, | ||
| setTokenUSDAmount, | ||
| }: InputAmountStepProps) => { | ||
| const router = useRouter() | ||
| const currencyData = useCurrency(selectedCountry.currency ?? 'ARS') | ||
|
|
||
| if (currencyData.isLoading) { | ||
| return <PeanutLoading /> | ||
| } | ||
|
|
||
| return ( | ||
| <div className="flex min-h-[inherit] flex-col justify-start space-y-8"> | ||
| <NavHeader title="Add Money" onPrev={() => router.back()} /> | ||
| <div className="my-auto flex flex-grow flex-col justify-center gap-4 md:my-0"> | ||
| <div className="text-sm font-bold">How much do you want to add?</div> | ||
|
|
||
| <TokenAmountInput | ||
| tokenValue={tokenAmount} | ||
| setTokenValue={(e) => setTokenAmount(e ?? '')} | ||
| walletBalance={undefined} | ||
| hideCurrencyToggle | ||
| setUsdValue={(e) => setTokenUSDAmount(e)} | ||
| currency={ | ||
| currencyData | ||
| ? { | ||
| code: currencyData.code!, | ||
| symbol: currencyData.symbol!, | ||
| price: currencyData.price!, | ||
| } | ||
| : undefined | ||
| } | ||
| hideBalance={true} | ||
| /> | ||
| <div className="flex items-center gap-2 text-xs text-grey-1"> | ||
| <Icon name="info" width={16} height={16} /> | ||
| <span>This must exactly match what you send from your bank</span> | ||
| </div> | ||
| <Button | ||
| variant="purple" | ||
| shadowSize="4" | ||
| onClick={onSubmit} | ||
| disabled={isLoading || !parseFloat(tokenAmount.replace(/,/g, ''))} | ||
| className="w-full" | ||
| loading={isLoading} | ||
| > | ||
| Continue | ||
| </Button> | ||
| {error && <ErrorAlert description={error} />} | ||
| </div> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export default InputAmountStep |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { MERCADO_PAGO } from '@/assets' | ||
| import Card from '@/components/Global/Card' | ||
| import PeanutActionDetailsCard from '@/components/Global/PeanutActionDetailsCard' | ||
| import { PaymentInfoRow } from '@/components/Payment/PaymentInfoRow' | ||
| import { PEANUT_WALLET_TOKEN_SYMBOL } from '@/constants' | ||
|
|
||
| interface MantecaDepositCardProps { | ||
| countryCodeForFlag: string | ||
| currencySymbol: string | ||
| amount: string | ||
| cbu?: string | ||
| alias?: string | ||
| depositAddress?: string | ||
| pixKey?: string | ||
| isMercadoPago: boolean | ||
| } | ||
|
|
||
| const MantecaDepositCard = ({ | ||
| countryCodeForFlag, | ||
| currencySymbol, | ||
| amount, | ||
| cbu, | ||
| alias, | ||
| depositAddress, | ||
| pixKey, | ||
| isMercadoPago, | ||
| }: MantecaDepositCardProps) => { | ||
| return ( | ||
| <div className="my-auto flex h-full w-full flex-col justify-center space-y-4"> | ||
| <PeanutActionDetailsCard | ||
| avatarSize="small" | ||
| transactionType="ADD_MONEY_BANK_ACCOUNT" | ||
| recipientType="BANK_ACCOUNT" | ||
| recipientName="Your Bank Account" | ||
| amount={amount} | ||
| tokenSymbol={PEANUT_WALLET_TOKEN_SYMBOL} | ||
| countryCodeForFlag={countryCodeForFlag} | ||
| currencySymbol={currencySymbol} | ||
| logo={isMercadoPago ? MERCADO_PAGO : undefined} | ||
| /> | ||
|
|
||
| <h2 className="font-bold">Account details</h2> | ||
| <Card className="rounded-sm"> | ||
| {cbu && <PaymentInfoRow label={'CBU'} value={cbu} allowCopy={true} />} | ||
| {alias && <PaymentInfoRow label={'Alias'} value={alias} hideBottomBorder />} | ||
| {depositAddress && <PaymentInfoRow label={'Deposit Address'} value={depositAddress} hideBottomBorder />} | ||
| {pixKey && <PaymentInfoRow label={'Pix Key'} value={pixKey} hideBottomBorder />} | ||
| </Card> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export default MantecaDepositCard |
79 changes: 79 additions & 0 deletions
79
src/components/AddMoney/components/RegionalMethods/MercadoPago/MercadoPagoDepositDetails.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| 'use client' | ||
|
|
||
| import NavHeader from '@/components/Global/NavHeader' | ||
| import { useParams, useRouter } from 'next/navigation' | ||
| import React, { useMemo } from 'react' | ||
| import { countryCodeMap, countryData } from '../../../consts' | ||
| import MantecaDepositCard from '../../MantecaDepositCard' | ||
| import ShareButton from '@/components/Global/ShareButton' | ||
| import { MantecaDepositDetails } from '@/types/manteca.types' | ||
|
|
||
| const MercadoPagoDepositDetails = ({ | ||
| depositDetails, | ||
| source, | ||
| }: { | ||
| depositDetails: MantecaDepositDetails | ||
| source: 'bank' | 'regionalMethod' | ||
| }) => { | ||
| const router = useRouter() | ||
| const params = useParams() | ||
| const currentCountryName = params.country as string | ||
|
|
||
| const currentCountryDetails = useMemo(() => { | ||
| // check if we have country params (from dynamic route) | ||
| if (currentCountryName) { | ||
| return countryData.find( | ||
| (country) => country.type === 'country' && country.path === currentCountryName.toLowerCase() | ||
| ) | ||
| } | ||
| // Default to Argentina | ||
| return countryData.find((c) => c.id === 'AR') | ||
| }, [currentCountryName]) | ||
|
|
||
| const countryCodeForFlag = useMemo(() => { | ||
| const countryId = currentCountryDetails?.id || 'AR' | ||
| return countryId.toLowerCase() | ||
| }, [currentCountryDetails]) | ||
|
|
||
| const generateShareText = () => { | ||
| const textParts = [] | ||
| const currencySymbol = currentCountryDetails?.currency || 'ARS' | ||
|
|
||
| textParts.push(`Amount: ${currencySymbol} ${depositDetails.depositAmount}`) | ||
|
|
||
| if (depositDetails.depositAddress) { | ||
| textParts.push(`CBU: ${depositDetails.depositAddress}`) | ||
| } | ||
| if (depositDetails.depositAlias) { | ||
| textParts.push(`Alias: ${depositDetails.depositAlias}`) | ||
| } | ||
|
|
||
| return textParts.join('\n') | ||
| } | ||
|
|
||
| return ( | ||
| <div className="flex h-full w-full flex-col justify-start gap-8 self-start"> | ||
| <NavHeader title={'Add Money'} onPrev={() => router.back()} /> | ||
|
|
||
| <MantecaDepositCard | ||
| countryCodeForFlag={countryCodeForFlag} | ||
| currencySymbol={currentCountryDetails?.currency || 'ARS'} | ||
| amount={depositDetails.depositAmount} | ||
| cbu={depositDetails.depositAddress} | ||
| alias={depositDetails.depositAlias} | ||
| isMercadoPago={source === 'regionalMethod'} | ||
| /> | ||
|
|
||
| <ShareButton | ||
| generateText={async () => generateShareText()} | ||
| title="Bank Transfer Details" | ||
| variant="purple" | ||
| className="w-full" | ||
| > | ||
| Share Details | ||
| </ShareButton> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export default MercadoPagoDepositDetails |
77 changes: 77 additions & 0 deletions
77
src/components/AddMoney/components/RegionalMethods/MercadoPago/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import React, { FC, useMemo, useState } from 'react' | ||
| import MercadoPagoDepositDetails from './MercadoPagoDepositDetails' | ||
| import InputAmountStep from '../../InputAmountStep' | ||
| import { createMantecaOnramp } from '@/app/actions/onramp' | ||
| import { useParams } from 'next/navigation' | ||
| import { countryData } from '@/components/AddMoney/consts' | ||
| import { MantecaDepositDetails } from '@/types/manteca.types' | ||
|
|
||
| interface MercadoPagoProps { | ||
| source: 'bank' | 'regionalMethod' | ||
| } | ||
|
|
||
| type stepType = 'inputAmount' | 'depositDetails' | ||
|
|
||
| const MercadoPago: FC<MercadoPagoProps> = ({ source }) => { | ||
| const params = useParams() | ||
| const [step, setStep] = useState<stepType>('inputAmount') | ||
| const [isCreatingDeposit, setIsCreatingDeposit] = useState(false) | ||
| const [tokenAmount, setTokenAmount] = useState('') | ||
| const [tokenUSDAmount, setTokenUSDAmount] = useState('') | ||
| const [error, setError] = useState<string | null>(null) | ||
| const [depositDetails, setDepositDetails] = useState<MantecaDepositDetails>() | ||
|
|
||
| const selectedCountryPath = params.country as string | ||
| const selectedCountry = useMemo(() => { | ||
| return countryData.find((country) => country.type === 'country' && country.path === selectedCountryPath) | ||
| }, [selectedCountryPath]) | ||
|
|
||
| const handleAmountSubmit = async () => { | ||
| if (!selectedCountry?.currency) return | ||
| if (isCreatingDeposit) return | ||
|
|
||
| try { | ||
| setError(null) | ||
| setIsCreatingDeposit(true) | ||
| const depositData = await createMantecaOnramp({ | ||
| usdAmount: tokenUSDAmount.replace(/,/g, ''), | ||
| currency: selectedCountry.currency, | ||
| }) | ||
| if (depositData.error) { | ||
| setError(depositData.error) | ||
| return | ||
| } | ||
| setDepositDetails(depositData.data) | ||
| setStep('depositDetails') | ||
| } catch (error) { | ||
| console.log(error) | ||
| setError(error instanceof Error ? error.message : String(error)) | ||
| } finally { | ||
| setIsCreatingDeposit(false) | ||
| } | ||
| } | ||
|
|
||
| if (!selectedCountry) return null | ||
|
|
||
| if (step === 'inputAmount') { | ||
| return ( | ||
| <InputAmountStep | ||
| tokenAmount={tokenAmount} | ||
| setTokenAmount={setTokenAmount} | ||
| onSubmit={handleAmountSubmit} | ||
| selectedCountry={selectedCountry} | ||
| isLoading={isCreatingDeposit} | ||
| error={error} | ||
| setTokenUSDAmount={setTokenUSDAmount} | ||
| /> | ||
| ) | ||
| } | ||
|
|
||
| if (step === 'depositDetails' && depositDetails) { | ||
| return <MercadoPagoDepositDetails source={source} depositDetails={depositDetails} /> | ||
| } | ||
|
|
||
| return null | ||
| } | ||
|
|
||
| export default MercadoPago |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.