Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matt/validate signing wallet #14

Merged
merged 3 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 28 additions & 9 deletions components/forms/TransactionSigning.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useAppContext } from "../../context/AppContext";
import Button from "../inputs/Button";
import HashView from "../dataViews/HashView";
import StackableContainer from "../layout/StackableContainer";
import { AminoTypes } from "@cosmjs/stargate";
import { pubkeyToAddress } from "@cosmjs/amino";

const TransactionSigning = (props) => {
const { state } = useAppContext();
Expand All @@ -32,6 +32,13 @@ const TransactionSigning = (props) => {
window.keplr_wallet = tempWalletAccount;
};

const isValidSigner =
props.accountOnChain &&
props.accountOnChain.pubkey.value.pubkeys.find(
(pubkey) =>
pubkeyToAddress(pubkey, state.chain.addressPrefix) === walletAccount.bech32Address,
);

const signTransaction = async () => {
window.keplr.defaultOptions = {
sign: {
Expand Down Expand Up @@ -86,7 +93,7 @@ const TransactionSigning = (props) => {
<p>You've signed this transaction.</p>
</div>
</StackableContainer>
) : (
) : isValidSigner ? (
<>
<h2>Sign this transaction</h2>
{walletAccount ? (
Expand All @@ -95,6 +102,11 @@ const TransactionSigning = (props) => {
<Button label="Connect Wallet" onClick={connectWallet} />
)}
</>
) : (
<>
<h2>The connected wallet is not a valid signer</h2>
<h3>Try switching wallets</h3>
</>
)}
{sigError && (
<StackableContainer lessPadding lessRadius lessMargin>
Expand All @@ -105,13 +117,20 @@ const TransactionSigning = (props) => {
)}
<h2>Current Signers</h2>
<StackableContainer lessPadding lessMargin lessRadius>
{props.signatures.map((signature, i) => (
<StackableContainer lessPadding lessRadius lessMargin key={`${signature.address}_${i}`}>
<HashView hash={signature.address} />
</StackableContainer>
))}

{props.signatures.length === 0 && <p>No signatures yet</p>}
{props.accountOnChain
? props.accountOnChain.pubkey.value.pubkeys.map((pubkey, i) => (
<StackableContainer lessPadding lessRadius lessMargin key={i}>
{props.signatures.find(
(s) => s.address === pubkeyToAddress(pubkey, state.chain.addressPrefix),
) ? (
<span>✅ Signature received</span>
) : (
<span>⌛ Waiting for signature</span>
)}
<HashView hash={pubkeyToAddress(pubkey, state.chain.addressPrefix)} />
</StackableContainer>
))
: null}
</StackableContainer>
<style jsx>{`
p {
Expand Down
2 changes: 2 additions & 0 deletions pages/multi/[address]/transaction/[transactionID].js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const transactionPage = ({
const client = await StargateClient.connect(state.chain.nodeAddress);
const tempHoldings = await client.getBalance(address, state.chain.denom);
const tempAccountOnChain = await getMultisigAccount(address, client);
console.log("MULTI", tempAccountOnChain);
setHoldings(tempHoldings);
setAccountOnChain(tempAccountOnChain);
} catch (error) {
Expand Down Expand Up @@ -146,6 +147,7 @@ const transactionPage = ({
{!transactionHash && (
<TransactionSigning
tx={txInfo}
accountOnChain={accountOnChain}
transactionID={transactionID}
signatures={currentSignatures}
addSignature={addSignature}
Expand Down