Skip to content

Commit db2d51c

Browse files
authored
Merge pull request #577 from Peersyst/feat/send-all-balance-front
Feat/send all funds
2 parents 6c99f50 + b37dd14 commit db2d51c

File tree

10 files changed

+54
-21
lines changed

10 files changed

+54
-21
lines changed

src/locale/locales/el/common.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,5 +226,6 @@
226226
"edit": "Επεξεργασία",
227227
"purchaseCompleted": "Η αγορά ολοκληρώθηκε!",
228228
"orderCompletedText": "Θυμηθείτε ότι θα χρειαστούν λίγα λεπτά για να αντικατοπτρίσει ο λογαριασμός σας το νέο ποσό.",
229-
"selectAddressOfDomain": "{{count}} διευθύνσεις CKB εντοπίστηκαν κάτω από τη διεύθυνση {{domain}}:"
229+
"selectAddressOfDomain": "{{count}} διευθύνσεις CKB εντοπίστηκαν κάτω από τη διεύθυνση {{domain}}:",
230+
"sendAllBalance": "Αποστολή όλου του υπολοίπου"
230231
}

src/locale/locales/en/common.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,5 +226,6 @@
226226
"edit": "Edit",
227227
"purchaseCompleted": "Purchase completed!",
228228
"orderCompletedText": "Remember that it will take a few minutes for your account balance to reflect the new amount.",
229-
"selectAddressOfDomain": "{{count}} CKB addresses detected under {{domain}} address:"
229+
"selectAddressOfDomain": "{{count}} CKB addresses detected under {{domain}} address:",
230+
"sendAllBalance": "Send all balance"
230231
}

src/locale/locales/es/common.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,5 +226,6 @@
226226
"edit": "Editar",
227227
"purchaseCompleted": "Compra completada!",
228228
"orderCompletedText": "Recuerda que tomará unos minutos para que el saldo de tu cuenta refleje tu nuevo balance.",
229-
"selectAddressOfDomain": "{{count}} direcciones CKB detectadas bajo la dirección {{domain}}:"
229+
"selectAddressOfDomain": "{{count}} direcciones CKB detectadas bajo la dirección {{domain}}:",
230+
"sendAllBalance": "Enviar todo el saldo"
230231
}

src/locale/locales/fr/common.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,5 +226,6 @@
226226
"edit": "Modifier",
227227
"purchaseCompleted": "Achat terminé!",
228228
"orderCompletedText": "Rappelez-vous qu'il faudra quelques minutes pour que le solde de votre compte reflète le nouveau montant.",
229-
"selectAddressOfDomain": "{{count}} adresses CKB détectées sous l'adresse {{domain}}:"
229+
"selectAddressOfDomain": "{{count}} adresses CKB détectées sous l'adresse {{domain}}:",
230+
"sendAllBalance": "Envoyer tout le solde"
230231
}

src/locale/locales/pt/common.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,5 +226,6 @@
226226
"edit": "Editar",
227227
"purchaseCompleted": "Compra concluída!",
228228
"orderCompletedText": "Lembre-se de que levará alguns minutos para que o saldo da sua conta reflita o novo valor.",
229-
"selectAddressOfDomain": "{{count}} endereços CKB detectados sob o endereço {{domain}}:"
229+
"selectAddressOfDomain": "{{count}} endereços CKB detectados sob o endereço {{domain}}:",
230+
"sendAllBalance": "Enviar todo o saldo"
230231
}

src/locale/locales/zh/common.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,5 +226,6 @@
226226
"edit": "编辑",
227227
"purchaseCompleted": "购买完成!",
228228
"orderCompletedText": "请记住,您的账户余额将需要几分钟才能反映出新的金额。",
229-
"selectAddressOfDomain": "在{{domain}}地址下检测到{{count}}个CKB地址:"
229+
"selectAddressOfDomain": "在{{domain}}地址下检测到{{count}}个CKB地址:",
230+
"sendAllBalance": "发送所有余额"
230231
}

src/module/transaction/hook/useSend.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ export interface UseSendTransactionReturn extends SignStatus {
1818
}
1919

2020
export function useSend(): UseSendTransactionReturn {
21-
const { senderWalletIndex = 0, asset, amount = "0", receiver, receiverDomainAddress }: SendState = useRecoilValue(sendState);
21+
const {
22+
senderWalletIndex = 0,
23+
asset,
24+
amount = "0",
25+
receiver,
26+
receiverDomainAddress,
27+
sendAllFunds,
28+
}: SendState = useRecoilValue(sendState);
2229
const sendCKBMutationResult = useSendCKB(senderWalletIndex);
2330
const sendFTMutationResult = useSendTokens(senderWalletIndex);
2431
const sendNFTsMutationResult = useSendNFT(senderWalletIndex);
@@ -90,6 +97,7 @@ export function useSend(): UseSendTransactionReturn {
9097
{
9198
amount: convertCKBToShannons(amount),
9299
to: receiverAddress!,
100+
sendAllFunds,
93101
feeRate: fee,
94102
},
95103
{

src/module/transaction/screen/SendConfirmationScreen/SendConfirmationScreen.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import useServiceInstance from "module/wallet/hook/useServiceInstance";
88
import { useSend } from "module/transaction/hook/useSend";
99
import SendModal from "module/transaction/component/core/SendModal/SendModal";
1010
import CallbackModal from "module/common/component/feedback/SignModal/SignModal";
11+
import useGetBalance from "module/wallet/query/useGetBalance";
1112

1213
const SendConfirmationScreen = (): JSX.Element => {
1314
const translate = useTranslate();
14-
const { amount, senderWalletIndex, receiver, receiverDomainAddress, message, asset } = useRecoilValue(sendState);
15+
const { amount, senderWalletIndex, receiver, receiverDomainAddress, message, asset, sendAllFunds } = useRecoilValue(sendState);
1516
const {
1617
state: { wallets },
1718
} = useWalletState();
@@ -27,13 +28,15 @@ const SendConfirmationScreen = (): JSX.Element => {
2728
hideModal(SendModal.id);
2829
}
2930

31+
const { data: { freeBalance = 0 } = {} } = useGetBalance(index);
32+
const amountToSend = sendAllFunds ? freeBalance : amount;
3033
return (
3134
<CallbackModal onSign={sendTransaction} {...restSendTransactionWithStatus} onError={closeSendModal} onExited={closeSendModal}>
3235
{({ showModal, isSuccess, isLoading }) => (
3336
<Col gap={24} onStartShouldSetResponder={() => true}>
3437
<SendSummary
3538
showTotal
36-
amount={amount!}
39+
amount={amountToSend!}
3740
receiverAddress={receiverAddress!}
3841
token={asset.ft}
3942
nft={asset.nft}

src/module/transaction/screen/SendSetAmountScreen/SendSetAmountScreen.tsx

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Col, Form, useSetTab, Suspense } from "@peersyst/react-native-components";
1+
import { Col, Form, useSetTab, Suspense, Switch } from "@peersyst/react-native-components";
22
import Button from "module/common/component/input/Button/Button";
33
import { useRecoilState } from "recoil";
44
import sendRecoilState, { SendState } from "module/transaction/state/SendState";
@@ -12,17 +12,19 @@ import { useState } from "react";
1212
import { Asset } from "module/wallet/wallet.types";
1313
import { AssetType } from "module/wallet/wallet.types";
1414

15-
export type SendAmountAndMessageResult = Pick<SendState, "amount" | "asset">;
15+
export type SendAmountAndMessageResult = Pick<SendState, "amount" | "asset" | "sendAllFunds">;
1616

1717
export const SEND_SET_AMOUNT_FORM_KEYS: Partial<Record<keyof SendState, keyof SendState>> = {
1818
asset: "asset",
1919
amount: "amount",
20+
sendAllFunds: "sendAllFunds",
2021
};
2122

2223
const SendSetAmountScreen = (): JSX.Element => {
2324
const [sendState, setSendState] = useRecoilState(sendRecoilState);
2425
const [asset, setAsset] = useState<Asset | undefined>(sendState.asset);
2526
const [amount, setAmount] = useState<string | undefined>(sendState.amount?.toString() ?? undefined);
27+
const [sendAllFunds, setSendAllFunds] = useState(false);
2628
const translate = useTranslate();
2729

2830
const senderWalletIndex = sendState.senderWalletIndex!;
@@ -53,16 +55,29 @@ const SendSetAmountScreen = (): JSX.Element => {
5355
index={senderWalletIndex}
5456
name={SEND_SET_AMOUNT_FORM_KEYS.asset}
5557
/>
56-
<AssetAmountTextField
57-
hideError={amount === ""}
58-
value={amount}
59-
onChange={(amount: string) => setAmount(amount)}
60-
label={translate("select_the_amount_to_send")}
61-
asset={asset ?? { type: AssetType.NATIVE_TOKEN }}
62-
placeholder={translate("enter_amount")}
63-
name={SEND_SET_AMOUNT_FORM_KEYS.amount}
64-
index={sendState.senderWalletIndex}
65-
/>
58+
59+
{!sendAllFunds && (
60+
<AssetAmountTextField
61+
hideError={amount === "" || sendAllFunds}
62+
value={amount}
63+
onChange={(amount: string) => setAmount(amount)}
64+
label={translate("select_the_amount_to_send")}
65+
asset={asset ?? { type: AssetType.NATIVE_TOKEN }}
66+
placeholder={translate("enter_amount")}
67+
name={SEND_SET_AMOUNT_FORM_KEYS.amount}
68+
index={sendState.senderWalletIndex}
69+
disabled={sendAllFunds}
70+
/>
71+
)}
72+
73+
{asset && asset.type === AssetType.NATIVE_TOKEN && (
74+
<Switch
75+
label={translate("sendAllBalance")}
76+
name={SEND_SET_AMOUNT_FORM_KEYS.sendAllFunds}
77+
value={sendAllFunds}
78+
onChange={setSendAllFunds}
79+
/>
80+
)}
6681
<Button variant="primary" type="submit" fullWidth>
6782
{translate("next")}
6883
</Button>

src/module/transaction/state/SendState.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface SendState {
99
message?: string;
1010
receiverDomainAddress?: BitAccountRecordAddress;
1111
asset: Asset;
12+
sendAllFunds?: boolean;
1213
}
1314

1415
const sendState = atom<SendState>({

0 commit comments

Comments
 (0)