Skip to content

Commit

Permalink
Clean up ConfirmTx
Browse files Browse the repository at this point in the history
  • Loading branch information
jurevans committed Jul 25, 2023
1 parent 3eaeda8 commit 5f1ae75
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 45 deletions.
3 changes: 1 addition & 2 deletions apps/extension/src/Approvals/ApproveTx/ApproveTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const ApproveTx: React.FC<Props> = ({ setDetails }) => {
return (
<ApprovalContainer>
<p>
Approve this <strong>{TxTypeLabel[txType as TxType]}</strong>
Approve this <strong>{TxTypeLabel[txType as TxType]}</strong>{" "}
transaction?
</p>
<p>Source:&nbsp;</p>
Expand All @@ -90,7 +90,6 @@ export const ApproveTx: React.FC<Props> = ({ setDetails }) => {
<p>
Amount: {amount} {tokenType}
</p>

<ButtonContainer>
<Button onClick={handleApproveClick} variant={ButtonVariant.Contained}>
Approve
Expand Down
3 changes: 1 addition & 2 deletions apps/extension/src/Approvals/ApproveTx/ConfirmLedgerTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const ConfirmLedgerTx: React.FC<Props> = ({ details }) => {
new GetRevealPKBytesMsg(toBase64(encoded))
);

// Sign with Ledgeg
// Sign with Ledger
const signatures = await ledger.sign(bytes, path);

// Submit signatures for tx
Expand Down Expand Up @@ -113,7 +113,6 @@ export const ConfirmLedgerTx: React.FC<Props> = ({ details }) => {
}
}, [source, publicKey]);

// TODO: This will not be necessary when `submit_signed_tx` is implemented!
const submitByType = async (
bytes: Uint8Array,
signatures: ResponseSign,
Expand Down
82 changes: 41 additions & 41 deletions apps/extension/src/Approvals/ApproveTx/ConfirmTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,57 +48,57 @@ export const ConfirmTx: React.FC<Props> = ({ details }) => {
`Decrypting keys and submitting ${TxTypeLabel[txType as TxType]}...`
);

switch (txType) {
case TxType.Bond: {
await requester.sendMessage(
Ports.Background,
new SubmitApprovedBondMsg(msgId, password)
);
setStatusInfo("");
setStatus(Status.Completed);
break;
}
case TxType.Transfer: {
const hasMaspParams = await requester.sendMessage(
Ports.Background,
new HasMaspParamsMsg()
);
try {
switch (txType) {
case TxType.Bond: {
await requester.sendMessage(
Ports.Background,
new SubmitApprovedBondMsg(msgId, password)
);
setStatusInfo("");
setStatus(Status.Completed);
break;
}
case TxType.Transfer: {
const hasMaspParams = await requester.sendMessage(
Ports.Background,
new HasMaspParamsMsg()
);

if (!hasMaspParams) {
setStatusInfo("Fetching MASP parameters...");
try {
await requester.sendMessage(
Ports.Background,
new FetchAndStoreMaspParamsMsg()
);
} catch (e) {
setError(`Fetching MASP parameters failed: ${e}`);
setStatus(Status.Failed);
if (!hasMaspParams) {
setStatusInfo("Fetching MASP parameters...");
try {
await requester.sendMessage(
Ports.Background,
new FetchAndStoreMaspParamsMsg()
);
} catch (e) {
setError(`Fetching MASP parameters failed: ${e}`);
setStatus(Status.Failed);
}
}
}
try {
await requester.sendMessage(
Ports.Background,
new SubmitApprovedTransferMsg(msgId, password)
);
setStatusInfo("");
setStatus(Status.Completed);
} catch (e) {
console.info(e);
setError(`${e}`);
setStatus(Status.Failed);
break;
}
case TxType.Unbond: {
await requester.sendMessage(
Ports.Background,
new SubmitApprovedUnbondMsg(msgId, password)
);
setStatusInfo("");
setStatus(Status.Completed);
break;
}
break;
}
case TxType.Unbond: {
await requester.sendMessage(
Ports.Background,
new SubmitApprovedUnbondMsg(msgId, password)
);
setStatusInfo("");
setStatus(Status.Completed);
break;
}
} catch (e) {
console.info(e);
setError(`${e}`);
setStatus(Status.Failed);
}
}, [password]);

Expand Down

0 comments on commit 5f1ae75

Please sign in to comment.