From 8dd3f1b142feb5836ac9dae7722eed622bb2b232 Mon Sep 17 00:00:00 2001
From: abefernan <44572727+abefernan@users.noreply.github.com>
Date: Fri, 21 Apr 2023 22:29:42 +0200
Subject: [PATCH 1/5] Fix typo in field
---
types/index.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/types/index.ts b/types/index.ts
index f6e78f1..16c5879 100644
--- a/types/index.ts
+++ b/types/index.ts
@@ -39,7 +39,7 @@ export interface DbAccount {
export interface WalletAccount {
address?: Uint8Array;
- pubkey: Uint8Array;
+ pubKey: Uint8Array;
algo: string;
bech32Address: string;
isNanoLedger?: boolean;
From a84a6981b1f11f2b352d14c1abe5f43eebd674f3 Mon Sep 17 00:00:00 2001
From: abefernan <44572727+abefernan@users.noreply.github.com>
Date: Fri, 21 Apr 2023 22:30:24 +0200
Subject: [PATCH 2/5] Add pubkey prop to TransactionSigning
---
components/forms/TransactionSigning.tsx | 3 ++-
pages/multi/[address]/transaction/[transactionID].tsx | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/components/forms/TransactionSigning.tsx b/components/forms/TransactionSigning.tsx
index f1b0c2d..1d477e9 100644
--- a/components/forms/TransactionSigning.tsx
+++ b/components/forms/TransactionSigning.tsx
@@ -1,4 +1,4 @@
-import { makeCosmoshubPath } from "@cosmjs/amino";
+import { MultisigThresholdPubkey, makeCosmoshubPath } from "@cosmjs/amino";
import { toBase64 } from "@cosmjs/encoding";
import { LedgerSigner } from "@cosmjs/ledger-amino";
import { SigningStargateClient } from "@cosmjs/stargate";
@@ -21,6 +21,7 @@ interface LoadingStates {
interface Props {
signatures: DbSignature[];
tx: DbTransaction;
+ pubkey: MultisigThresholdPubkey;
transactionID: string;
addSignature: (signature: DbSignature) => void;
}
diff --git a/pages/multi/[address]/transaction/[transactionID].tsx b/pages/multi/[address]/transaction/[transactionID].tsx
index d67c41e..dac3082 100644
--- a/pages/multi/[address]/transaction/[transactionID].tsx
+++ b/pages/multi/[address]/transaction/[transactionID].tsx
@@ -168,10 +168,11 @@ const TransactionPage = ({
{broadcastError &&
{broadcastError}
}
>
)}
- {!transactionHash && (
+ {!transactionHash && !!pubkey && (
From 71cd088c594a993c26e399488a5ba49eb6d46a65 Mon Sep 17 00:00:00 2001
From: abefernan <44572727+abefernan@users.noreply.github.com>
Date: Fri, 21 Apr 2023 22:31:10 +0200
Subject: [PATCH 3/5] Implement signing states
---
components/forms/TransactionSigning.tsx | 72 ++++++++++++++++++-------
1 file changed, 54 insertions(+), 18 deletions(-)
diff --git a/components/forms/TransactionSigning.tsx b/components/forms/TransactionSigning.tsx
index 1d477e9..250ea62 100644
--- a/components/forms/TransactionSigning.tsx
+++ b/components/forms/TransactionSigning.tsx
@@ -12,6 +12,8 @@ import HashView from "../dataViews/HashView";
import Button from "../inputs/Button";
import StackableContainer from "../layout/StackableContainer";
+type SigningStatus = "not_signed" | "not_a_member" | "signed";
+
interface LoadingStates {
readonly signing?: boolean;
readonly keplr?: boolean;
@@ -27,10 +29,12 @@ interface Props {
}
const TransactionSigning = (props: Props) => {
+ const memberPubkeys = props.pubkey?.value.pubkeys.map(({ value }) => value);
+
const { state } = useAppContext();
const [walletAccount, setWalletAccount] = useState();
const [sigError, setSigError] = useState("");
- const [hasSigned, setHasSigned] = useState(false);
+ const [signing, setSigning] = useState("not_signed");
const [walletType, setWalletType] = useState<"Keplr" | "Ledger">();
const [ledgerSigner, setLedgerSigner] = useState({});
const [loading, setLoading] = useState({});
@@ -45,12 +49,23 @@ const TransactionSigning = (props: Props) => {
sign: { preferNoSetFee: true, preferNoSetMemo: true, disableBalanceCheck: true },
};
const tempWalletAccount = await window.keplr.getKey(state.chain.chainId);
- console.log(tempWalletAccount);
- const tempHasSigned = props.signatures.some(
- (sig) => sig.address === tempWalletAccount.bech32Address,
- );
setWalletAccount(tempWalletAccount);
- setHasSigned(tempHasSigned);
+
+ const pubkey = toBase64(tempWalletAccount.pubKey);
+ const isMember = memberPubkeys.includes(pubkey);
+ const hasSigned = isMember
+ ? props.signatures.some((sig) => sig.address === tempWalletAccount.bech32Address)
+ : false;
+ if (hasSigned) {
+ setSigning("signed");
+ }
+ if (isMember && !hasSigned) {
+ setSigning("not_signed");
+ }
+ if (!isMember) {
+ setSigning("not_a_member");
+ }
+
setWalletType("Keplr");
} catch (e) {
console.log("enable keplr err: ", e);
@@ -72,20 +87,29 @@ const TransactionSigning = (props: Props) => {
hdPaths: [makeCosmoshubPath(0)],
prefix: state.chain.addressPrefix,
});
- console.log(offlineSigner);
const accounts = await offlineSigner.getAccounts();
- console.log(accounts);
const tempWalletAccount: WalletAccount = {
bech32Address: accounts[0].address,
- pubkey: accounts[0].pubkey,
+ pubKey: accounts[0].pubkey,
algo: accounts[0].algo,
};
-
- const tempHasSigned = props.signatures.some(
- (sig) => sig.address === tempWalletAccount.bech32Address,
- );
setWalletAccount(tempWalletAccount);
- setHasSigned(tempHasSigned);
+
+ const pubkey = toBase64(tempWalletAccount.pubKey);
+ const isMember = memberPubkeys.includes(pubkey);
+ const hasSigned = isMember
+ ? props.signatures.some((sig) => sig.address === tempWalletAccount.bech32Address)
+ : false;
+ if (hasSigned) {
+ setSigning("signed");
+ }
+ if (isMember && !hasSigned) {
+ setSigning("not_signed");
+ }
+ if (!isMember) {
+ setSigning("not_a_member");
+ }
+
setLedgerSigner(offlineSigner);
setWalletType("Ledger");
} catch (e) {
@@ -143,7 +167,7 @@ const TransactionSigning = (props: Props) => {
signature,
);
props.addSignature(signature);
- setHasSigned(true);
+ setSigning("signed");
}
} catch (e) {
console.log("signing err: ", e);
@@ -154,7 +178,7 @@ const TransactionSigning = (props: Props) => {
return (
- {hasSigned ? (
+ {signing === "signed" ? (
- ) : (
+ ) : null}
+ {signing === "not_a_member" ? (
+
+
+
You don't belong to this multisig.
+
+
+ ) : null}
+ {signing === "not_signed" ? (
<>
Sign this transaction
@@ -191,7 +223,7 @@ const TransactionSigning = (props: Props) => {
)}
>
- )}
+ ) : null}
{sigError && (
@@ -242,6 +274,10 @@ const TransactionSigning = (props: Props) => {
height: 0.8em;
margin-right: 0.5em;
}
+ .multisig-error p {
+ color: red;
+ font-size: 16px;
+ }
`}
);
From 09f6151eaf7840b5eb8ea812746b4ad442b6d773 Mon Sep 17 00:00:00 2001
From: abefernan <44572727+abefernan@users.noreply.github.com>
Date: Mon, 24 Apr 2023 22:22:27 +0200
Subject: [PATCH 4/5] Remove optional chaining
---
components/forms/TransactionSigning.tsx | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/components/forms/TransactionSigning.tsx b/components/forms/TransactionSigning.tsx
index 250ea62..8a417e6 100644
--- a/components/forms/TransactionSigning.tsx
+++ b/components/forms/TransactionSigning.tsx
@@ -29,7 +29,7 @@ interface Props {
}
const TransactionSigning = (props: Props) => {
- const memberPubkeys = props.pubkey?.value.pubkeys.map(({ value }) => value);
+ const memberPubkeys = props.pubkey.value.pubkeys.map(({ value }) => value);
const { state } = useAppContext();
const [walletAccount, setWalletAccount] = useState();
From 7be71457619ec994f9cd0c51f1d5b0c7a5a56f3f Mon Sep 17 00:00:00 2001
From: abefernan <44572727+abefernan@users.noreply.github.com>
Date: Mon, 24 Apr 2023 22:22:45 +0200
Subject: [PATCH 5/5] Refactor setSigning
---
components/forms/TransactionSigning.tsx | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/components/forms/TransactionSigning.tsx b/components/forms/TransactionSigning.tsx
index 8a417e6..cffdfbc 100644
--- a/components/forms/TransactionSigning.tsx
+++ b/components/forms/TransactionSigning.tsx
@@ -56,14 +56,14 @@ const TransactionSigning = (props: Props) => {
const hasSigned = isMember
? props.signatures.some((sig) => sig.address === tempWalletAccount.bech32Address)
: false;
- if (hasSigned) {
- setSigning("signed");
- }
- if (isMember && !hasSigned) {
- setSigning("not_signed");
- }
if (!isMember) {
setSigning("not_a_member");
+ } else {
+ if (hasSigned) {
+ setSigning("signed");
+ } else {
+ setSigning("not_signed");
+ }
}
setWalletType("Keplr");
@@ -100,14 +100,14 @@ const TransactionSigning = (props: Props) => {
const hasSigned = isMember
? props.signatures.some((sig) => sig.address === tempWalletAccount.bech32Address)
: false;
- if (hasSigned) {
- setSigning("signed");
- }
- if (isMember && !hasSigned) {
- setSigning("not_signed");
- }
if (!isMember) {
setSigning("not_a_member");
+ } else {
+ if (hasSigned) {
+ setSigning("signed");
+ } else {
+ setSigning("not_signed");
+ }
}
setLedgerSigner(offlineSigner);