Skip to content

Commit

Permalink
Merge pull request #14 from umee-network/matt/validate-signing-wallet
Browse files Browse the repository at this point in the history
Matt/validate signing wallet
  • Loading branch information
dreamcodez authored Feb 25, 2022
2 parents 0b54ea7 + 8cb3f3f commit e1ff870
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
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

1 comment on commit e1ff870

@vercel
Copy link

@vercel vercel bot commented on e1ff870 Feb 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.