forked from binary-com/deriv-app
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cashier-V2] george / FEQ-19 / Wrap the components into Payment Agent…
… Withdrawal module (binary-com#14376) * feat(cashier-v2): ⚡ add payment agent withdrawal module * perf(cashier-v2): 🎨 replace successfull state with status * refactor(cashier-v2): restructure payment agent modules folder
- Loading branch information
1 parent
c4d7009
commit f095005
Showing
48 changed files
with
725 additions
and
152 deletions.
There are no files selected for viewing
This file contains 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 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,14 @@ | ||
import useMutation from '../useMutation'; | ||
|
||
/** A custom hook to request paymentagent withdrawal */ | ||
const usePaymentAgentWithdrawal = () => { | ||
const { data, ...rest } = useMutation('paymentagent_withdraw'); | ||
|
||
/** Paymentagent withdrawal response */ | ||
return { | ||
data, | ||
...rest, | ||
}; | ||
}; | ||
|
||
export default usePaymentAgentWithdrawal; |
This file contains 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 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
39 changes: 39 additions & 0 deletions
39
packages/cashier-v2/src/flows/PaymentAgent/PaymentAgent.tsx
This file contains 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,39 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { PageContainer } from '../../components'; | ||
import { PaymentAgentWithdrawalModule, WithdrawalVerificationModule } from '../../lib'; | ||
|
||
const PaymentAgent = () => { | ||
const [verificationCode, setVerificationCode] = useState('1'); | ||
|
||
useEffect(() => { | ||
const queryParams = new URLSearchParams(location.search); | ||
const verificationQueryParam = queryParams.get('verification'); | ||
|
||
if (verificationQueryParam) { | ||
setVerificationCode(verificationQueryParam); | ||
|
||
const url = new URL(window.location.href); | ||
url.searchParams.delete('verification'); // Remove the 'verification_code' query parameter | ||
window.history.replaceState({}, document.title, url.toString()); | ||
} | ||
}, []); | ||
|
||
if (verificationCode) { | ||
return ( | ||
<PageContainer> | ||
<PaymentAgentWithdrawalModule | ||
setVerificationCode={setVerificationCode} | ||
verificationCode={verificationCode} | ||
/> | ||
</PageContainer> | ||
); | ||
} | ||
|
||
return ( | ||
<PageContainer> | ||
<WithdrawalVerificationModule withdrawalType='paymentagent_withdraw' /> | ||
</PageContainer> | ||
); | ||
}; | ||
|
||
export default PaymentAgent; |
This file contains 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 @@ | ||
export { default as PaymentAgent } from './PaymentAgent'; |
Empty file.
This file contains 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 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { AccountTransfer } from './AccountTransfer'; | ||
export { Deposit } from './Deposit'; | ||
export { PaymentAgent } from './PaymentAgent'; | ||
export { PaymentAgentTransfer } from './PaymentAgentTransfer'; | ||
export { Withdrawal } from './Withdrawal'; |
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...ymentAgentDeposit/PaymentAgentDeposit.tsx → ...ymentAgentDeposit/PaymentAgentDeposit.tsx
This file contains 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 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
File renamed without changes.
13 changes: 13 additions & 0 deletions
13
...cashier-v2/src/lib/PaymentAgent/PaymentAgentWithdrawal/PaymentAgentWithdrawal.module.scss
This file contains 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,13 @@ | ||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1.6rem; | ||
margin: 0 auto; | ||
} | ||
|
||
.unlisted-withdrawal-link { | ||
&:hover { | ||
text-decoration: underline; | ||
cursor: pointer; | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
packages/cashier-v2/src/lib/PaymentAgent/PaymentAgentWithdrawal/PaymentAgentWithdrawal.tsx
This file contains 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,69 @@ | ||
import React, { useCallback } from 'react'; | ||
import { Loader, Text } from '@deriv-com/ui'; | ||
import { clickAndKeyEventHandler } from '../../../utils'; | ||
import { PaymentAgentList, PaymentAgentSearchContainer } from '../components'; | ||
import { PaymentAgentProvider, usePaymentAgentContext } from '../provider'; | ||
import { | ||
PaymentAgentUnlistedWithdrawalForm, | ||
PaymentAgentWithdrawalConfirm, | ||
PaymentAgentWithdrawalReceipt, | ||
} from './components'; | ||
import { PaymentAgentWithdrawalProvider, usePaymentAgentWithdrawalContext } from './provider'; | ||
import type { TPaymentAgentWithdrawalModuleProps } from './types'; | ||
import styles from './PaymentAgentWithdrawal.module.scss'; | ||
|
||
const PaymentAgentWithdrawal = () => { | ||
const { isPaymentAgentListLoading } = usePaymentAgentContext(); | ||
const { isUnlistedWithdrawal, setIsUnlistedWithdrawal, withdrawalStatus } = usePaymentAgentWithdrawalContext(); | ||
|
||
const showUnlistedWithdrawalForm = useCallback( | ||
(e?: React.KeyboardEvent<HTMLElement> | React.MouseEvent<HTMLElement>) => { | ||
clickAndKeyEventHandler(() => setIsUnlistedWithdrawal(true), e); | ||
}, | ||
[setIsUnlistedWithdrawal] | ||
); | ||
|
||
if (isPaymentAgentListLoading) return <Loader />; | ||
|
||
if (withdrawalStatus === 'try_successful') return <PaymentAgentWithdrawalConfirm />; | ||
|
||
if (withdrawalStatus === 'successful') return <PaymentAgentWithdrawalReceipt />; | ||
|
||
if (isUnlistedWithdrawal) return <PaymentAgentUnlistedWithdrawalForm />; | ||
|
||
return ( | ||
<div className={styles.container}> | ||
<Text size='sm'> | ||
Choose your preferred payment agent and enter your withdrawal amount. If your payment agent is not | ||
listed,{' '} | ||
<Text className={styles['unlisted-withdrawal-link']} color='red' size='sm' weight='bold'> | ||
<span onClick={showUnlistedWithdrawalForm} onKeyDown={showUnlistedWithdrawalForm}> | ||
search for them using their account number | ||
</span> | ||
</Text> | ||
. | ||
</Text> | ||
<PaymentAgentSearchContainer> | ||
<PaymentAgentList /> | ||
</PaymentAgentSearchContainer> | ||
</div> | ||
); | ||
}; | ||
|
||
const PaymentAgentWithdrawalModule: React.FC<TPaymentAgentWithdrawalModuleProps> = ({ | ||
setVerificationCode, | ||
verificationCode, | ||
}) => { | ||
return ( | ||
<PaymentAgentProvider> | ||
<PaymentAgentWithdrawalProvider | ||
setVerificationCode={setVerificationCode} | ||
verificationCode={verificationCode} | ||
> | ||
<PaymentAgentWithdrawal /> | ||
</PaymentAgentWithdrawalProvider> | ||
</PaymentAgentProvider> | ||
); | ||
}; | ||
|
||
export default PaymentAgentWithdrawalModule; |
This file contains 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 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
File renamed without changes.
Oops, something went wrong.