Skip to content

Commit d74306d

Browse files
committed
refactor: cashouts component
1 parent 7eeafec commit d74306d

File tree

5 files changed

+51
-29
lines changed

5 files changed

+51
-29
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { useTranslation } from "next-i18next";
2+
import { ReactElement, useMemo } from "react";
3+
4+
5+
6+
interface AddressDisplayProps {
7+
walletAddress: string;
8+
description: string;
9+
triggerEditAddress: () => void;
10+
}
11+
/**
12+
* Address display component
13+
*
14+
* @returns {ReactElement}
15+
*/
16+
export default function AddressDisplay({ walletAddress, description, triggerEditAddress }: AddressDisplayProps): ReactElement {
17+
const { t } = useTranslation();
18+
const address = useMemo(() => (walletAddress ? walletAddress.match(/.{1,4}/g) : null), [walletAddress]);
19+
return (
20+
<div className="text-sm text-gray-700">
21+
{address ? (
22+
<p className="leading-5 text-sm flex gap-x-2 gap-y-1 flex-wrap font-mono font-normal">
23+
{address.map((part, index) => (
24+
<span key={`address-${index}`} className="mr-2">
25+
{part}
26+
</span>
27+
))}
28+
</p>
29+
) : (
30+
<p>{description}</p>
31+
)}
32+
<div className="text-gray-700 text-sm mt-3">
33+
<span className="cursor-pointer hover:underline" onClick={triggerEditAddress}>
34+
{address ? t("profile.wallets.address-change") : t("profile.wallets.address-set")}
35+
</span>
36+
</div>
37+
</div>
38+
);
39+
}

src/components/cards/wallet/CashoutAddress.tsx renamed to src/components/cards/wallet/_partials/Cashout.tsx

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import { useSelector } from "@/hooks/useTypedSelector";
77
import { openVerificationModal } from "@/store/feature/kyc.slice";
88
import { Wallet } from "@/types/wallet";
99
import { ReactElement, useCallback, useMemo } from "react";
10+
import AddressDisplay from "./AddressDisplay";
1011

11-
interface CashoutAddressProps {
12+
interface CashoutProps {
1213
wallet: Wallet;
1314
setShowEditModal: (show: boolean) => void;
1415
disabled: boolean;
@@ -21,12 +22,11 @@ interface CashoutAddressProps {
2122
*
2223
* @returns {ReactElement}
2324
*/
24-
export default function CashoutAddress({ wallet, setShowEditModal, disabled, setShowPayoutModal, testId = "cashoutAddressId" }: CashoutAddressProps): ReactElement {
25+
export default function Cashout({ wallet, setShowEditModal, disabled, setShowPayoutModal, testId = "cashoutAddressId" }: CashoutProps): ReactElement {
2526
const { t } = useTranslation();
2627
const dispatch = useDispatch();
2728
const user = useSelector((state) => state.user.data);
28-
const isKycVerified = user?.kycStatus === "VERIFIED";
29-
const address = useMemo(() => (wallet.address ? wallet.address.match(/.{1,4}/g) : null), [wallet.address]);
29+
const isKycVerified = useMemo(() => user?.kycStatus === "VERIFIED", [user?.kycStatus]);
3030
const cashable = useMemo(() => String(wallet.token).toUpperCase() !== "DAC", [wallet.token]);
3131

3232
const triggerEditAddress = useCallback(() => {
@@ -58,24 +58,7 @@ export default function CashoutAddress({ wallet, setShowEditModal, disabled, set
5858
return (
5959
<div className="px-7 pt-6 flex-1 pb-24 lg:pb-24" data-testid={testId}>
6060
{cashable ? (
61-
<div className="text-sm text-gray-700">
62-
{address ? (
63-
<p className="leading-5 text-sm flex gap-x-2 gap-y-1 flex-wrap font-mono font-normal">
64-
{address.map((part, index) => (
65-
<span key={`address-${index}`} className="mr-2">
66-
{part}
67-
</span>
68-
))}
69-
</p>
70-
) : (
71-
<p>{wallet.description}</p>
72-
)}
73-
<div className="text-gray-700 text-sm mt-3">
74-
<span className="cursor-pointer hover:underline" onClick={triggerEditAddress}>
75-
{address ? t("profile.wallets.address-change") : t("profile.wallets.address-set")}
76-
</span>
77-
</div>
78-
</div>
61+
<AddressDisplay walletAddress={wallet.address} description={wallet.description} triggerEditAddress={triggerEditAddress} />
7962
) : (
8063
<div className="prose">
8164
<p

src/components/cards/wallet/WalletHint.tsx renamed to src/components/cards/wallet/_partials/Hints.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Hint from "@/components/ui/Hint";
44
import { useTranslation } from "next-i18next";
55
import { ReactElement } from "react";
66

7-
interface WalletHintProps {
7+
interface HintsProps {
88
wallet: Wallet;
99
}
1010

@@ -14,7 +14,7 @@ interface WalletHintProps {
1414
* @returns {ReactElement}
1515
*/
1616

17-
export default function WalletHint({ wallet }: WalletHintProps): ReactElement {
17+
export default function Hints({ wallet }: HintsProps): ReactElement {
1818
const { t } = useTranslation();
1919
return (
2020
<>
File renamed without changes.

src/components/cards/wallet/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import Payout from "@/components/sections/profile/modals/Payout";
44
import { Wallet } from "@/types/wallet";
55
import { toggleBodyScrolling } from "@/store/feature/ui.slice";
66
import { useDispatch } from "@/hooks/useTypedDispatch";
7-
import CashoutAddress from "./CashoutAddress";
8-
import Overview from "./Overview";
9-
import WalletHint from "./WalletHint";
7+
import Cashout from "./_partials/Cashout";
8+
import Overview from "./_partials/Overview";
9+
import Hints from "./_partials/Hints";
1010

1111
/**
1212
* Cards wallet props interface
@@ -40,9 +40,9 @@ export default function CardsWallet({ wallet, disabled = false, testId = "cardWa
4040
{showEditModal && <EditAddress show={showEditModal} onClose={onClose} wallet={wallet} />}
4141
<Payout wallet={wallet} show={showPayoutModal} onClose={onClose} />
4242
<Overview wallet={wallet} />
43-
<CashoutAddress wallet={wallet} setShowEditModal={setShowEditModal} disabled={disabled} setShowPayoutModal={setShowPayoutModal} />
43+
<Cashout wallet={wallet} setShowEditModal={setShowEditModal} disabled={disabled} setShowPayoutModal={setShowPayoutModal} />
4444
</div>
45-
<WalletHint wallet={wallet} />
45+
<Hints wallet={wallet} />
4646
</div>
4747
);
4848
}

0 commit comments

Comments
 (0)