Skip to content
Merged
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
23 changes: 14 additions & 9 deletions src/components/Claim/Link/views/BankFlowManager.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ import { useWebSocket } from '@/hooks/useWebSocket'
import { KYCStatus } from '@/utils/bridge-accounts.utils'
import { getCountryCodeForWithdraw } from '@/utils/withdraw.utils'

type BankAccountWithId = IBankAccountDetails &
(
| { id: string; bridgeAccountId: string }
| { id: string; bridgeAccountId?: string }
| { id?: string; bridgeAccountId: string }
)

/**
* @name BankFlowManager
* @description This component manages the entire bank claim flow, acting as a state machine.
Expand Down Expand Up @@ -60,7 +67,7 @@ export const BankFlowManager = (props: IClaimScreenProps) => {
const { claimLink } = useClaimLink()

// local states for this component
const [localBankDetails, setLocalBankDetails] = useState<IBankAccountDetails | null>(null)
const [localBankDetails, setLocalBankDetails] = useState<BankAccountWithId | null>(null)
const [receiverFullName, setReceiverFullName] = useState<string>('')
const [error, setError] = useState<string | null>(null)
const formRef = useRef<{ handleSubmit: () => void }>(null)
Expand Down Expand Up @@ -113,9 +120,7 @@ export const BankFlowManager = (props: IClaimScreenProps) => {
* @name handleCreateOfframpAndClaim
* @description creates an off-ramp transfer for the user, either as a guest or a logged-in user.
*/
const handleCreateOfframpAndClaim = async (
account: IBankAccountDetails & { id?: string; bridgeAccountId?: string }
) => {
const handleCreateOfframpAndClaim = async (account: BankAccountWithId) => {
try {
setLoadingState('Executing transaction')
setError(null)
Expand Down Expand Up @@ -150,9 +155,7 @@ export const BankFlowManager = (props: IClaimScreenProps) => {
const contractVersion = params.contractVersion
const peanutContractAddress = peanut.getContractAddress(chainId, contractVersion) as Address

const externalAccountId = account?.bridgeAccountId ?? account?.id

if (!externalAccountId) throw new Error('External account ID not found')
const externalAccountId = (account.bridgeAccountId ?? account.id) as string

const destination = getOfframpCurrencyConfig(account.country ?? selectedCountry!.id)

Expand Down Expand Up @@ -242,7 +245,7 @@ export const BankFlowManager = (props: IClaimScreenProps) => {
return { error: addBankAccountResponse.error }
}
if (addBankAccountResponse.data?.id) {
const bankDetails: IBankAccountDetails & { id?: string; bridgeAccountId?: string } = {
const bankDetails = {
name: addBankAccountResponse.data.details.accountOwnerName || user?.user.fullName || '',
iban:
addBankAccountResponse.data.type === 'iban'
Expand Down Expand Up @@ -317,6 +320,8 @@ export const BankFlowManager = (props: IClaimScreenProps) => {

// merge the external account details with the user's details
const finalBankDetails = {
id: externalAccountResponse.id,
bridgeAccountId: externalAccountResponse.id,
name: externalAccountResponse.bank_name ?? rawData.name,
firstName: externalAccountResponse.first_name ?? rawData.firstName,
lastName: externalAccountResponse.last_name ?? rawData.lastName,
Expand Down Expand Up @@ -378,7 +383,7 @@ export const BankFlowManager = (props: IClaimScreenProps) => {
).split(' ')
const lastName = lastNameParts.join(' ')

const bankDetails: IBankAccountDetails & { id?: string; bridgeAccountId?: string } = {
const bankDetails = {
name: account.details.accountOwnerName || user?.user.fullName || '',
iban: account.type === 'iban' ? account.identifier || '' : '',
clabe: account.type === 'clabe' ? account.identifier || '' : '',
Expand Down
Loading