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
40 changes: 37 additions & 3 deletions src/app/(mobile-ui)/withdraw/manteca/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export default function MantecaWithdrawFlow() {
// intent is passed at call time: handleInitiateKyc('LATAM')
const sumsubFlow = useMultiPhaseKycFlow({})
const [showKycModal, setShowKycModal] = useState(false)
const [isRedirectingToOnboarding, setIsRedirectingToOnboarding] = useState(false)
// Get method and country from URL parameters
const selectedMethodType = searchParams.get('method') // mercadopago, pix, bank-transfer, etc.
const countryFromUrl = searchParams.get('country') // argentina, brazil, etc.
Expand Down Expand Up @@ -176,6 +177,29 @@ export default function MantecaWithdrawFlow() {
return isValid
}

/**
* Detect Manteca onboarding-incomplete errors and redirect user to complete their profile.
* Returns true if the error was handled (caller should return early).
*/
const handleOnboardingError = useCallback(async (error: string): Promise<boolean> => {
const onboardingErrorPatterns = ['fund origin', 'profile incomplete', 'onboarding required']
const normalizedError = error.toLowerCase()
const isOnboardingError = onboardingErrorPatterns.some((pattern) => normalizedError.includes(pattern))
if (!isOnboardingError) return false

setIsRedirectingToOnboarding(true)
try {
const result = await mantecaApi.initiateOnboarding({
returnUrl: window.location.href,
})
window.location.href = result.url
} catch {
setErrorMessage('Please complete your account setup. Go to Settings to update your profile.')
setIsRedirectingToOnboarding(false)
}
return true
}, [])

const isCompleteBankDetails = useMemo<boolean>(() => {
return (
!!destinationAddress.trim() &&
Expand Down Expand Up @@ -215,6 +239,7 @@ export default function MantecaWithdrawFlow() {
})

if (result.error) {
if (await handleOnboardingError(result.error)) return
setErrorMessage(result.error)
return
}
Expand Down Expand Up @@ -244,6 +269,7 @@ export default function MantecaWithdrawFlow() {
currencyAmount,
isUserMantecaKycApproved,
isLockingPrice,
handleOnboardingError,
])

const handleWithdraw = async () => {
Expand Down Expand Up @@ -314,6 +340,9 @@ export default function MantecaWithdrawFlow() {
error_message: result.error,
})

// handle onboarding-incomplete errors by redirecting to complete profile
if (await handleOnboardingError(result.message ?? result.error)) return

// handle third-party account error with user-friendly message
if (result.error === 'TAX_ID_MISMATCH' || result.error === 'CUIT_MISMATCH') {
setErrorMessage('You can only withdraw to accounts under your name.')
Expand Down Expand Up @@ -664,13 +693,18 @@ export default function MantecaWithdrawFlow() {
!isCompleteBankDetails ||
isDestinationAddressChanging ||
!isDestinationAddressValid ||
isLockingPrice
isLockingPrice ||
isRedirectingToOnboarding
}
loading={isDestinationAddressChanging || isLockingPrice}
loading={isDestinationAddressChanging || isLockingPrice || isRedirectingToOnboarding}
className="w-full"
shadowSize="4"
>
{isLockingPrice ? 'Locking rate...' : 'Review'}
{isRedirectingToOnboarding
? 'Redirecting...'
: isLockingPrice
? 'Locking rate...'
: 'Review'}
</Button>

{errorMessage && <ErrorAlert description={errorMessage} />}
Expand Down
Loading