Merge pull request #113 from cosmos/fix/sig-account-number

Assert accountNumber in forms
This commit is contained in:
Abel Fernández
2023-04-25 11:05:00 +02:00
committed by GitHub
7 changed files with 56 additions and 43 deletions
+2 -2
View File
@@ -12,7 +12,7 @@ import StackableContainer from "../layout/StackableContainer";
interface Props {
delegatorAddress: string;
accountOnChain: Account | null;
accountOnChain: Account;
router: NextRouter;
closeForm: () => void;
}
@@ -49,7 +49,7 @@ const DelegationForm = (props: Props) => {
assert(gasPrice, "gasPrice missing");
const fee = calculateFee(gasLimit, gasPrice);
const { accountOnChain } = props;
assert(accountOnChain, "accountOnChain missing");
assert(typeof accountOnChain.accountNumber === "number", "accountNumber missing");
return {
accountNumber: accountOnChain.accountNumber,
sequence: accountOnChain.sequence,
+2 -2
View File
@@ -12,7 +12,7 @@ import StackableContainer from "../layout/StackableContainer";
interface Props {
delegatorAddress: string;
accountOnChain: Account | null;
accountOnChain: Account;
router: NextRouter;
closeForm: () => void;
}
@@ -56,7 +56,7 @@ const ReDelegationForm = (props: Props) => {
assert(gasPrice, "gasPrice missing");
const fee = calculateFee(gasLimit, gasPrice);
const { accountOnChain } = props;
assert(accountOnChain, "accountOnChain missing");
assert(typeof accountOnChain.accountNumber === "number", "accountNumber missing");
return {
accountNumber: accountOnChain.accountNumber,
sequence: accountOnChain.sequence,
+2 -2
View File
@@ -11,7 +11,7 @@ import StackableContainer from "../layout/StackableContainer";
interface Props {
delegatorAddress: string;
accountOnChain: Account | null;
accountOnChain: Account;
router: NextRouter;
closeForm: () => void;
}
@@ -39,7 +39,7 @@ const RewardsForm = (props: Props) => {
assert(gasPrice, "gasPrice missing");
const fee = calculateFee(gasLimit, gasPrice);
const { accountOnChain } = props;
assert(accountOnChain, "accountOnChain missing");
assert(typeof accountOnChain.accountNumber === "number", "accountNumber missing");
return {
accountNumber: accountOnChain.accountNumber,
sequence: accountOnChain.sequence,
+2 -2
View File
@@ -12,7 +12,7 @@ import StackableContainer from "../layout/StackableContainer";
interface Props {
address: string | null;
accountOnChain: Account | null;
accountOnChain: Account;
router: NextRouter;
closeForm: () => void;
}
@@ -51,7 +51,7 @@ const TransactionForm = (props: Props) => {
assert(gasPrice, "gasPrice missing");
const fee = calculateFee(gasLimit, gasPrice);
const { accountOnChain } = props;
assert(accountOnChain, "accountOnChain missing");
assert(typeof accountOnChain.accountNumber === "number", "accountNumber missing");
return {
accountNumber: accountOnChain.accountNumber,
sequence: accountOnChain.sequence,
+1
View File
@@ -50,6 +50,7 @@ const UnDelegationForm = (props: Props) => {
const fee = calculateFee(gasLimit, gasPrice);
const { accountOnChain } = props;
assert(accountOnChain, "accountOnChain missing");
assert(typeof accountOnChain.accountNumber === "number", "accountNumber missing");
return {
accountNumber: accountOnChain.accountNumber,
sequence: accountOnChain.sequence,
+43 -35
View File
@@ -112,35 +112,35 @@ const Multipage = () => {
</div>
</StackableContainer>
)}
{txView === "send" && (
{txView === "send" && accountOnChain && (
<TransactionForm
address={multisigAddress}
accountOnChain={accountOnChain}
closeForm={closeForm}
/>
)}
{txView === "delegate" && (
{txView === "delegate" && accountOnChain && (
<DelegationForm
delegatorAddress={multisigAddress}
accountOnChain={accountOnChain}
closeForm={closeForm}
/>
)}
{txView === "undelegate" && (
{txView === "undelegate" && accountOnChain && (
<UnDelegationForm
delegatorAddress={multisigAddress}
accountOnChain={accountOnChain}
closeForm={closeForm}
/>
)}
{txView === "redelegate" && (
{txView === "redelegate" && accountOnChain && (
<ReDelegationForm
delegatorAddress={multisigAddress}
accountOnChain={accountOnChain}
closeForm={closeForm}
/>
)}
{txView === "claimRewards" && (
{txView === "claimRewards" && accountOnChain && (
<RewardsForm
delegatorAddress={multisigAddress}
accountOnChain={accountOnChain}
@@ -159,36 +159,44 @@ const Multipage = () => {
Once a transaction is created, it can be signed by the multisig members, and then
broadcast.
</p>
<Button
label="Create Transaction"
onClick={() => {
setTxView("send");
}}
/>
<Button
label="Create Delegation"
onClick={() => {
setTxView("delegate");
}}
/>
<Button
label="Create UnDelegation"
onClick={() => {
setTxView("undelegate");
}}
/>
<Button
label="Create Redelegate"
onClick={() => {
setTxView("redelegate");
}}
/>
<Button
label="Claim Rewards"
onClick={() => {
setTxView("claimRewards");
}}
/>
{accountOnChain ? (
<>
<Button
label="Create Transaction"
onClick={() => {
setTxView("send");
}}
/>
<Button
label="Create Delegation"
onClick={() => {
setTxView("delegate");
}}
/>
<Button
label="Create UnDelegation"
onClick={() => {
setTxView("undelegate");
}}
/>
<Button
label="Create Redelegate"
onClick={() => {
setTxView("redelegate");
}}
/>
<Button
label="Claim Rewards"
onClick={() => {
setTxView("claimRewards");
}}
/>
</>
) : (
<p>
An account needs to be present on chain before creating a transaction. Send some tokens to the address first.
</p>
)}
</StackableContainer>
</div>
</div>
@@ -113,6 +113,10 @@ const TransactionPage = ({
setBroadcastError("");
assert(accountOnChain, "Account on chain value missing.");
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(