From f108b017b3a32d639bc61c946ca292eff1f45b06 Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Mon, 24 Apr 2023 08:41:27 +0200 Subject: [PATCH 1/5] Assert accountNumber in forms --- components/forms/DelegationForm.tsx | 1 + components/forms/ReDelegationForm.tsx | 1 + components/forms/RewardsForm.tsx | 1 + components/forms/TransactionForm.tsx | 1 + components/forms/UnDelegationForm.tsx | 1 + pages/multi/[address]/transaction/[transactionID].tsx | 1 + 6 files changed, 6 insertions(+) diff --git a/components/forms/DelegationForm.tsx b/components/forms/DelegationForm.tsx index 8cb44ab..611794a 100644 --- a/components/forms/DelegationForm.tsx +++ b/components/forms/DelegationForm.tsx @@ -50,6 +50,7 @@ const DelegationForm = (props: Props) => { const fee = calculateFee(gasLimit, gasPrice); const { accountOnChain } = props; assert(accountOnChain, "accountOnChain missing"); + assert(accountOnChain.accountNumber, "accountNumber missing"); return { accountNumber: accountOnChain.accountNumber, sequence: accountOnChain.sequence, diff --git a/components/forms/ReDelegationForm.tsx b/components/forms/ReDelegationForm.tsx index 5ada999..65c70e8 100644 --- a/components/forms/ReDelegationForm.tsx +++ b/components/forms/ReDelegationForm.tsx @@ -57,6 +57,7 @@ const ReDelegationForm = (props: Props) => { const fee = calculateFee(gasLimit, gasPrice); const { accountOnChain } = props; assert(accountOnChain, "accountOnChain missing"); + assert(accountOnChain.accountNumber, "accountNumber missing"); return { accountNumber: accountOnChain.accountNumber, sequence: accountOnChain.sequence, diff --git a/components/forms/RewardsForm.tsx b/components/forms/RewardsForm.tsx index c4a16d0..3ee2dcf 100644 --- a/components/forms/RewardsForm.tsx +++ b/components/forms/RewardsForm.tsx @@ -40,6 +40,7 @@ const RewardsForm = (props: Props) => { const fee = calculateFee(gasLimit, gasPrice); const { accountOnChain } = props; assert(accountOnChain, "accountOnChain missing"); + assert(accountOnChain.accountNumber, "accountNumber missing"); return { accountNumber: accountOnChain.accountNumber, sequence: accountOnChain.sequence, diff --git a/components/forms/TransactionForm.tsx b/components/forms/TransactionForm.tsx index 3d22d75..6fd0f6f 100644 --- a/components/forms/TransactionForm.tsx +++ b/components/forms/TransactionForm.tsx @@ -52,6 +52,7 @@ const TransactionForm = (props: Props) => { const fee = calculateFee(gasLimit, gasPrice); const { accountOnChain } = props; assert(accountOnChain, "accountOnChain missing"); + assert(accountOnChain.accountNumber, "accountNumber missing"); return { accountNumber: accountOnChain.accountNumber, sequence: accountOnChain.sequence, diff --git a/components/forms/UnDelegationForm.tsx b/components/forms/UnDelegationForm.tsx index 50cb41f..0274bbf 100644 --- a/components/forms/UnDelegationForm.tsx +++ b/components/forms/UnDelegationForm.tsx @@ -50,6 +50,7 @@ const UnDelegationForm = (props: Props) => { const fee = calculateFee(gasLimit, gasPrice); const { accountOnChain } = props; assert(accountOnChain, "accountOnChain missing"); + assert(accountOnChain.accountNumber, "accountNumber missing"); return { accountNumber: accountOnChain.accountNumber, sequence: accountOnChain.sequence, diff --git a/pages/multi/[address]/transaction/[transactionID].tsx b/pages/multi/[address]/transaction/[transactionID].tsx index d67c41e..fe8d0b6 100644 --- a/pages/multi/[address]/transaction/[transactionID].tsx +++ b/pages/multi/[address]/transaction/[transactionID].tsx @@ -113,6 +113,7 @@ const TransactionPage = ({ setBroadcastError(""); assert(accountOnChain, "Account on chain value missing."); + assert(accountOnChain.accountNumber, "Account on chain is missing an accountNumber"); assert(pubkey, "Pubkey not found on chain or in database"); const bodyBytes = fromBase64(currentSignatures[0].bodyBytes); const signedTxBytes = makeMultisignedTxBytes( From 11499f078c1d7065e128396e658665705e72328e Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Mon, 24 Apr 2023 22:30:24 +0200 Subject: [PATCH 2/5] Account for falsy accountNumber --- components/forms/DelegationForm.tsx | 2 +- components/forms/ReDelegationForm.tsx | 2 +- components/forms/RewardsForm.tsx | 2 +- components/forms/TransactionForm.tsx | 2 +- components/forms/UnDelegationForm.tsx | 2 +- pages/multi/[address]/transaction/[transactionID].tsx | 5 ++++- 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/components/forms/DelegationForm.tsx b/components/forms/DelegationForm.tsx index 611794a..98e0773 100644 --- a/components/forms/DelegationForm.tsx +++ b/components/forms/DelegationForm.tsx @@ -50,7 +50,7 @@ const DelegationForm = (props: Props) => { const fee = calculateFee(gasLimit, gasPrice); const { accountOnChain } = props; assert(accountOnChain, "accountOnChain missing"); - assert(accountOnChain.accountNumber, "accountNumber missing"); + assert(typeof accountOnChain.accountNumber === "number", "accountNumber missing"); return { accountNumber: accountOnChain.accountNumber, sequence: accountOnChain.sequence, diff --git a/components/forms/ReDelegationForm.tsx b/components/forms/ReDelegationForm.tsx index 65c70e8..add2781 100644 --- a/components/forms/ReDelegationForm.tsx +++ b/components/forms/ReDelegationForm.tsx @@ -57,7 +57,7 @@ const ReDelegationForm = (props: Props) => { const fee = calculateFee(gasLimit, gasPrice); const { accountOnChain } = props; assert(accountOnChain, "accountOnChain missing"); - assert(accountOnChain.accountNumber, "accountNumber missing"); + assert(typeof accountOnChain.accountNumber === "number", "accountNumber missing"); return { accountNumber: accountOnChain.accountNumber, sequence: accountOnChain.sequence, diff --git a/components/forms/RewardsForm.tsx b/components/forms/RewardsForm.tsx index 3ee2dcf..e26dddb 100644 --- a/components/forms/RewardsForm.tsx +++ b/components/forms/RewardsForm.tsx @@ -40,7 +40,7 @@ const RewardsForm = (props: Props) => { const fee = calculateFee(gasLimit, gasPrice); const { accountOnChain } = props; assert(accountOnChain, "accountOnChain missing"); - assert(accountOnChain.accountNumber, "accountNumber missing"); + assert(typeof accountOnChain.accountNumber === "number", "accountNumber missing"); return { accountNumber: accountOnChain.accountNumber, sequence: accountOnChain.sequence, diff --git a/components/forms/TransactionForm.tsx b/components/forms/TransactionForm.tsx index 6fd0f6f..bdcc1db 100644 --- a/components/forms/TransactionForm.tsx +++ b/components/forms/TransactionForm.tsx @@ -52,7 +52,7 @@ const TransactionForm = (props: Props) => { const fee = calculateFee(gasLimit, gasPrice); const { accountOnChain } = props; assert(accountOnChain, "accountOnChain missing"); - assert(accountOnChain.accountNumber, "accountNumber missing"); + assert(typeof accountOnChain.accountNumber === "number", "accountNumber missing"); return { accountNumber: accountOnChain.accountNumber, sequence: accountOnChain.sequence, diff --git a/components/forms/UnDelegationForm.tsx b/components/forms/UnDelegationForm.tsx index 0274bbf..699c4dd 100644 --- a/components/forms/UnDelegationForm.tsx +++ b/components/forms/UnDelegationForm.tsx @@ -50,7 +50,7 @@ const UnDelegationForm = (props: Props) => { const fee = calculateFee(gasLimit, gasPrice); const { accountOnChain } = props; assert(accountOnChain, "accountOnChain missing"); - assert(accountOnChain.accountNumber, "accountNumber missing"); + assert(typeof accountOnChain.accountNumber === "number", "accountNumber missing"); return { accountNumber: accountOnChain.accountNumber, sequence: accountOnChain.sequence, diff --git a/pages/multi/[address]/transaction/[transactionID].tsx b/pages/multi/[address]/transaction/[transactionID].tsx index fe8d0b6..df4770b 100644 --- a/pages/multi/[address]/transaction/[transactionID].tsx +++ b/pages/multi/[address]/transaction/[transactionID].tsx @@ -113,7 +113,10 @@ const TransactionPage = ({ setBroadcastError(""); assert(accountOnChain, "Account on chain value missing."); - assert(accountOnChain.accountNumber, "Account on chain is missing an accountNumber"); + assert( + typeof accountOnChain.accountNumber === "number", + "Account on chain is missing an accountNumber", + ); assert(pubkey, "Pubkey not found on chain or in database"); const bodyBytes = fromBase64(currentSignatures[0].bodyBytes); const signedTxBytes = makeMultisignedTxBytes( From dfe68ccb89ded6ee7a74e3e69f2f415d668a495b Mon Sep 17 00:00:00 2001 From: abefernan <44572727+abefernan@users.noreply.github.com> Date: Mon, 24 Apr 2023 22:42:21 +0200 Subject: [PATCH 3/5] Add conditional rendering for null accountOnChain --- pages/multi/[address]/index.tsx | 78 ++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 35 deletions(-) diff --git a/pages/multi/[address]/index.tsx b/pages/multi/[address]/index.tsx index 6fb70a9..fe3d233 100644 --- a/pages/multi/[address]/index.tsx +++ b/pages/multi/[address]/index.tsx @@ -111,35 +111,35 @@ const Multipage = () => { )} - {txView === "send" && ( + {txView === "send" && accountOnChain && ( )} - {txView === "delegate" && ( + {txView === "delegate" && accountOnChain && ( )} - {txView === "undelegate" && ( + {txView === "undelegate" && accountOnChain && ( )} - {txView === "redelegate" && ( + {txView === "redelegate" && accountOnChain && ( )} - {txView === "claimRewards" && ( + {txView === "claimRewards" && accountOnChain && ( { Once a transaction is created, it can be signed by the multisig members, and then broadcast.

-