Skip to content

Commit 0ef1638

Browse files
authored
Node app new send flow (#290)
1 parent 90adf48 commit 0ef1638

File tree

22 files changed

+3071
-608
lines changed

22 files changed

+3071
-608
lines changed

renderer/components/AssetAmountInput/AssetAmountInput.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ export function AssetAmountInput({
5757
alt=""
5858
height="24"
5959
width="24"
60+
style={{
61+
borderRadius: "4px",
62+
}}
6063
/>
6164
{children}
6265
{selectedAsset?.asset.verification.status === "verified" && (

renderer/components/BridgeAssetsForm/BridgeAssetsForm.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ function BridgeAssetsFormContent({
143143
alt=""
144144
width="24"
145145
height="24"
146+
style={{
147+
borderRadius: "4px",
148+
}}
146149
/>
147150
<ItemText>{item.label}</ItemText>
148151
{item.asset.verification.status === "verified" && (

renderer/components/NoteRow/NoteRow.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ export function NoteRow({
211211
to,
212212
type,
213213
value,
214+
contact,
214215
]);
215216

216217
return (

renderer/components/SendAssetsForm/ConfirmLedgerModal/ConfirmLedgerModal.tsx

Lines changed: 82 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,18 @@
1-
import {
2-
Modal,
3-
ModalOverlay,
4-
ModalContent,
5-
ModalFooter,
6-
ModalBody,
7-
} from "@chakra-ui/react";
1+
import { Modal, ModalOverlay, ModalContent } from "@chakra-ui/react";
82
import { useCallback, useEffect, useState } from "react";
9-
import { useIntl, defineMessages } from "react-intl";
3+
import { useFormContext } from "react-hook-form";
104

115
import { AssetOptionType } from "@/components/AssetAmountInput/utils";
126
import { trpcReact, TRPCRouterOutputs } from "@/providers/TRPCProvider";
13-
import { PillButton } from "@/ui/PillButton/PillButton";
7+
import { normalizeTransactionData } from "@/utils/transactionUtils";
148

159
import { StepConfirm } from "./Steps/StepConfirm";
1610
import { StepConnect } from "./Steps/StepConnect";
1711
import { TransactionRejected } from "./Steps/TransactionRejected";
1812
import { ReviewTransaction } from "../SharedConfirmSteps/ReviewTransaction";
1913
import { SubmissionError } from "../SharedConfirmSteps/SubmissionError";
2014
import { TransactionSubmitted } from "../SharedConfirmSteps/TransactionSubmitted";
21-
import { TransactionData } from "../transactionSchema";
22-
23-
const messages = defineMessages({
24-
cancel: {
25-
defaultMessage: "Cancel",
26-
},
27-
continue: {
28-
defaultMessage: "Continue",
29-
},
30-
});
15+
import { TransactionFormData } from "../transactionSchema";
3116

3217
type LedgerStatus = {
3318
isLedgerConnected: boolean;
@@ -39,20 +24,21 @@ type LedgerStatus = {
3924

4025
type Props = {
4126
isOpen: boolean;
42-
transactionData: TransactionData;
4327
selectedAccount: TRPCRouterOutputs["getAccounts"][number];
44-
selectedAsset?: AssetOptionType;
28+
selectedAsset: AssetOptionType;
4529
onCancel: () => void;
30+
estimatedFeesData: TRPCRouterOutputs["getEstimatedFees"];
4631
};
4732

4833
export function ConfirmLedgerModal({
4934
isOpen,
5035
onCancel,
51-
transactionData,
5236
selectedAccount,
5337
selectedAsset,
38+
estimatedFeesData,
5439
}: Props) {
55-
const { formatMessage } = useIntl();
40+
const { watch } = useFormContext<TransactionFormData>();
41+
const transactionFormData = watch();
5642

5743
const [
5844
{ isLedgerConnected, isLedgerUnlocked, isIronfishAppOpen },
@@ -66,6 +52,7 @@ export function ConfirmLedgerModal({
6652
}));
6753

6854
const [_statusError, setStatusError] = useState("");
55+
const { setError } = useFormContext();
6956

7057
const [step, setStep] = useState<
7158
| "IDLE"
@@ -86,7 +73,7 @@ export function ConfirmLedgerModal({
8673

8774
useEffect(() => {
8875
if (
89-
!["CONNECT_LEDGER", "ERROR"].includes(step) &&
76+
!["CONNECT_LEDGER", "ERROR", "IDLE"].includes(step) &&
9077
(!isLedgerConnected || !isLedgerUnlocked || !isIronfishAppOpen)
9178
) {
9279
setStep("CONNECT_LEDGER");
@@ -120,6 +107,29 @@ export function ConfirmLedgerModal({
120107
}
121108
}, [isLedgerConnected, isLedgerUnlocked, isIronfishAppOpen, step]);
122109

110+
const handleSubmitTransaction = useCallback(() => {
111+
const { normalizedTransactionData, error } = normalizeTransactionData({
112+
transactionFormData,
113+
estimatedFeesData,
114+
selectedAsset,
115+
});
116+
if (error !== null) {
117+
setError("root.serverError", {
118+
message: error,
119+
});
120+
setStep("IDLE");
121+
} else {
122+
submitTransaction(normalizedTransactionData);
123+
setStep("CONFIRM_TRANSACTION");
124+
}
125+
}, [
126+
transactionFormData,
127+
estimatedFeesData,
128+
selectedAsset,
129+
submitTransaction,
130+
setError,
131+
]);
132+
123133
const handleClose = useCallback(() => {
124134
if (step === "CONFIRM_TRANSACTION") {
125135
cancelTransaction();
@@ -128,106 +138,58 @@ export function ConfirmLedgerModal({
128138
onCancel();
129139
}, [onCancel, reset, step, cancelTransaction]);
130140

141+
const stepMap = {
142+
IDLE: (
143+
<ReviewTransaction
144+
selectedAccount={selectedAccount}
145+
selectedAsset={selectedAsset}
146+
estimatedFeesData={estimatedFeesData}
147+
onClose={handleClose}
148+
onSubmit={() => {
149+
setStep("CONNECT_LEDGER");
150+
}}
151+
/>
152+
),
153+
CONNECT_LEDGER: (
154+
<StepConnect
155+
isLedgerConnected={isLedgerConnected}
156+
isLedgerUnlocked={isLedgerUnlocked}
157+
isIronfishAppOpen={isIronfishAppOpen}
158+
onCancel={handleClose}
159+
onContinue={handleSubmitTransaction}
160+
isLoading={isLoading}
161+
/>
162+
),
163+
CONFIRM_TRANSACTION: <StepConfirm onCancel={handleClose} />,
164+
TRANSACTION_SUBMITTED: (
165+
<TransactionSubmitted
166+
fromAccount={selectedAccount.name}
167+
transactionHash={submittedTransactionData?.hash ?? ""}
168+
handleClose={handleClose}
169+
/>
170+
),
171+
SUBMISSION_ERROR:
172+
error?.message === "TRANSACTION_REJECTED" ? (
173+
<TransactionRejected
174+
isLoading={isLoading}
175+
handleClose={handleClose}
176+
handleSubmit={handleSubmitTransaction}
177+
/>
178+
) : (
179+
<SubmissionError
180+
errorMessage={error?.message ?? ""}
181+
isLoading={isLoading}
182+
handleClose={handleClose}
183+
handleSubmit={handleSubmitTransaction}
184+
/>
185+
),
186+
};
187+
131188
return (
132189
<Modal isOpen={isOpen} onClose={handleClose}>
133190
<ModalOverlay />
134191
<ModalContent maxW="100%" width="600px">
135-
{step === "IDLE" && (
136-
<ReviewTransaction
137-
transactionData={transactionData}
138-
selectedAccount={selectedAccount}
139-
selectedAsset={selectedAsset}
140-
onClose={handleClose}
141-
onSubmit={() => {
142-
setStep("CONNECT_LEDGER");
143-
}}
144-
/>
145-
)}
146-
{step === "CONNECT_LEDGER" && (
147-
<>
148-
<ModalBody px={16} pt={16}>
149-
<StepConnect
150-
isLedgerConnected={isLedgerConnected}
151-
isLedgerUnlocked={isLedgerUnlocked}
152-
isIronfishAppOpen={isIronfishAppOpen}
153-
/>
154-
</ModalBody>
155-
<ModalFooter display="flex" gap={2} px={16} py={8}>
156-
<PillButton
157-
size="sm"
158-
onClick={handleClose}
159-
variant="inverted"
160-
border={0}
161-
>
162-
{formatMessage(messages.cancel)}
163-
</PillButton>
164-
<PillButton
165-
size="sm"
166-
isDisabled={
167-
isLoading ||
168-
!isLedgerConnected ||
169-
!isLedgerUnlocked ||
170-
!isIronfishAppOpen
171-
}
172-
onClick={() => {
173-
submitTransaction(transactionData);
174-
setStep("CONFIRM_TRANSACTION");
175-
}}
176-
>
177-
{formatMessage(messages.continue)}
178-
</PillButton>
179-
</ModalFooter>
180-
</>
181-
)}
182-
{step === "CONFIRM_TRANSACTION" && (
183-
<>
184-
<ModalBody px={16} pt={16}>
185-
<StepConfirm />
186-
</ModalBody>
187-
<ModalFooter display="flex" gap={2} px={16} py={8}>
188-
<PillButton
189-
size="sm"
190-
onClick={handleClose}
191-
variant="inverted"
192-
border={0}
193-
>
194-
{formatMessage(messages.cancel)}
195-
</PillButton>
196-
</ModalFooter>
197-
</>
198-
)}
199-
{step === "TRANSACTION_SUBMITTED" && (
200-
<TransactionSubmitted
201-
fromAccount={selectedAccount.name}
202-
transactionHash={submittedTransactionData?.hash ?? ""}
203-
handleClose={handleClose}
204-
/>
205-
)}
206-
207-
{step === "SUBMISSION_ERROR" &&
208-
error?.message === "TRANSACTION_REJECTED" && (
209-
<TransactionRejected
210-
isLoading={isLoading}
211-
handleClose={handleClose}
212-
handleSubmit={() => {
213-
submitTransaction(transactionData);
214-
setStep("CONFIRM_TRANSACTION");
215-
}}
216-
/>
217-
)}
218-
219-
{step === "SUBMISSION_ERROR" &&
220-
error?.message !== "TRANSACTION_REJECTED" && (
221-
<SubmissionError
222-
errorMessage={error?.message ?? ""}
223-
isLoading={isLoading}
224-
handleClose={handleClose}
225-
handleSubmit={() => {
226-
submitTransaction(transactionData);
227-
setStep("CONFIRM_TRANSACTION");
228-
}}
229-
/>
230-
)}
192+
{stepMap[step]}
231193
</ModalContent>
232194
</Modal>
233195
);
Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,37 @@
1-
import { Heading } from "@chakra-ui/react";
1+
import { Heading, ModalBody, ModalFooter } from "@chakra-ui/react";
22
import Image from "next/image";
33
import { useIntl, defineMessages } from "react-intl";
44

5+
import { PillButton } from "@/ui/PillButton/PillButton";
6+
57
import connectImage from "./assets/connect.svg";
68

79
const messages = defineMessages({
810
heading: {
911
defaultMessage: "Please approve the transaction on your device.",
1012
},
13+
cancel: {
14+
defaultMessage: "Cancel",
15+
},
1116
});
1217

13-
export function StepConfirm() {
18+
type Props = {
19+
onCancel: () => void;
20+
};
21+
22+
export function StepConfirm({ onCancel }: Props) {
1423
const { formatMessage } = useIntl();
1524
return (
1625
<>
17-
<Heading mb={4}>{formatMessage(messages.heading)}</Heading>
18-
<Image src={connectImage} alt="" />
26+
<ModalBody px={16} pt={16}>
27+
<Heading mb={4}>{formatMessage(messages.heading)}</Heading>
28+
<Image src={connectImage} alt="" />
29+
</ModalBody>
30+
<ModalFooter display="flex" gap={2} px={16} py={8}>
31+
<PillButton size="sm" onClick={onCancel} variant="inverted" border={0}>
32+
{formatMessage(messages.cancel)}
33+
</PillButton>
34+
</ModalFooter>
1935
</>
2036
);
2137
}

0 commit comments

Comments
 (0)