From d9d2e32cf85bd962f066f6b201dde07c6d7943d7 Mon Sep 17 00:00:00 2001 From: samepant Date: Sun, 11 Apr 2021 22:28:30 -0400 Subject: [PATCH] working transaction creation --- components/dataViews/MultisigHoldings.js | 31 +++--- components/dataViews/TransactionInfo.js | 43 ++++---- components/forms/TransactionForm.js | 100 ++++++++++-------- components/layout/StackableContainer.js | 3 +- db-schema.graphql | 13 +-- pages/api/transaction/[transactionID].js | 32 ++++++ pages/api/transaction/index.js | 33 ++++++ pages/multi/[address]/index.js | 48 +++++++-- ...transactionUUID].js => [transactionID].js} | 31 +++++- 9 files changed, 229 insertions(+), 105 deletions(-) create mode 100644 pages/api/transaction/[transactionID].js create mode 100644 pages/api/transaction/index.js rename pages/multi/[address]/transaction/{[transactionUUID].js => [transactionID].js} (51%) diff --git a/components/dataViews/MultisigHoldings.js b/components/dataViews/MultisigHoldings.js index 8195728..a247c16 100644 --- a/components/dataViews/MultisigHoldings.js +++ b/components/dataViews/MultisigHoldings.js @@ -1,15 +1,22 @@ import StackableContainer from "../layout/StackableContainer"; -export default (props) => ( - -

Holdings

- - 1,021,010 ATOM +export default (props) => { + const uatomToAtom = (uatom) => { + if (uatom === 0) return 0; + return uatom / 1000000; + }; + + return ( + +

Holdings

+ + {props.holdings} ATOM + +
- -
-); + ); +}; diff --git a/components/dataViews/TransactionInfo.js b/components/dataViews/TransactionInfo.js index 3482cb9..4948471 100644 --- a/components/dataViews/TransactionInfo.js +++ b/components/dataViews/TransactionInfo.js @@ -1,48 +1,43 @@ import { abbreviateLongString } from "../../lib/displayHelpers"; import StackableContainer from "../layout/StackableContainer"; +const uatomToAtom = (uatom) => { + return uatom / 1000000; +}; export default (props) => (
    - {props.tx.amount && ( + {props.tx.msgs && (
  • -
    {props.tx.amount} ATOM
    +
    {uatomToAtom(props.tx.msgs[0].value.amount[0].amount)} ATOM
  • )} - {props.tx.to && ( + {props.tx.msgs && (
  • -
    - {props.abbreviate ? abbreviateLongString(props.tx.to) : props.tx.to} +
    + {props.tx.abbreviate + ? abbreviateLongString(props.tx.msgs[0].value.toAddress) + : props.tx.msgs[0].value.toAddress}
  • )} - {props.tx.txHash && ( -
  • - -
    - {abbreviateLongString(props.tx.txHash)} -
    -
  • - )} - {props.tx.status && ( -
  • - -
    {props.tx.status}
    -
  • - )} +
  • + +
    {props.tx.status || "signing in progress"}
    +
  • {props.tx.fee && (
  • - -
    {props.tx.fee}
    + +
    {props.tx.fee.gas} UATOM
  • )} - {props.tx.time && ( + {props.tx.memo && (
  • - -
    {props.tx.time}
    + +
    {props.tx.memo}
  • )}
diff --git a/components/forms/TransactionForm.js b/components/forms/TransactionForm.js index 46ca4e2..bcecf82 100644 --- a/components/forms/TransactionForm.js +++ b/components/forms/TransactionForm.js @@ -1,4 +1,5 @@ import axios from "axios"; +import { coins } from "@cosmjs/launchpad"; import React from "react"; import { withRouter } from "next/router"; @@ -6,33 +7,6 @@ import Button from "../../components/inputs/Button"; import Input from "../../components/inputs/Input"; import StackableContainer from "../layout/StackableContainer"; -const baseTX = { - type: "cosmos-sdk/StdTx", - value: { - msg: [ - { - type: "cosmos-sdk/MsgSend", - value: { - from_address: "", - to_address: "", - amount: [ - { - denom: "uatom", - amount: "0", - }, - ], - }, - }, - ], - fee: { - amount: [], - gas: "0", - }, - signatures: null, - memo: "", - }, -}; - class TransactionForm extends React.Component { constructor(props) { super(props); @@ -54,10 +28,29 @@ class TransactionForm extends React.Component { }; createTransaction = (toAddress, amount, gas) => { - baseTX.value.msg[0].value.to_address = toAddress; - baseTX.value.msg[0].value.from_address = this.props.address; - baseTX.value.msg[0].value.amount[0].amount = amount.toString(); - baseTX.value.fee.gas = gas.toString(); + const msgSend = { + fromAddress: this.props.address, + toAddress: toAddress, + amount: coins(amount * 1000000, "uatom"), + }; + const msg = { + typeUrl: "/cosmos.bank.v1beta1.MsgSend", + value: msgSend, + }; + const gasLimit = gas; + const fee = { + amount: coins(2000, "uatom"), + gas: gasLimit.toString(), + }; + + return { + accountNumber: this.props.accountOnChain.accountNumber, + sequence: this.props.accountOnChain.sequence, + chainId: "cosmoshub-4", + msgs: [msg], + fee: fee, + memo: this.state.memo, + }; return baseTX; }; @@ -70,13 +63,11 @@ class TransactionForm extends React.Component { this.state.gas ); - const res = await axios.post("/api/transaction", { - unsignedJson: JSON.stringify(tx), - multiAddress: this.props.multiAddress, - }); - + const dataJSON = JSON.stringify(tx); + const res = await axios.post("/api/transaction", { dataJSON }); + const { transactionID } = res.data; this.props.router.push( - `${this.props.multiAddress}/transaction/${res.data}` + `${this.props.address}/transaction/${transactionID}` ); } else { this.setState({ addressError: "Use a valid cosmos-hub address" }); @@ -86,6 +77,9 @@ class TransactionForm extends React.Component { render() { return ( +

Create New transaction

@@ -107,21 +102,23 @@ class TransactionForm extends React.Component {
-