Skip to content

Commit

Permalink
MsgSend
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamcodez committed Feb 23, 2022
1 parent a340894 commit ffbc0d2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
13 changes: 9 additions & 4 deletions components/forms/FlexibleTransactionForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import CodeMirror from "@uiw/react-codemirror";
import MsgDelegate from "../messages/MsgDelegate";
import MsgUndelegate from "../messages/MsgUndelegate";
import MsgRedelegate from "../messages/MsgRedelegate";
import MsgSend from "../messages/MsgSend";
import MsgVote from "../messages/MsgVote";

const blankMessageJSON = `{
Expand All @@ -28,10 +29,12 @@ function blankSendJSON(fromAddress) {
value: {
fromAddress,
toAddress: "",
amount: {
denom: "uumee",
amount: "0",
},
amount: [
{
denom: "uumee",
amount: "0",
},
],
},
},
null,
Expand Down Expand Up @@ -189,6 +192,8 @@ const FlexibleTransactionForm = (props) => {

function getMsgUI(msg, onMsgChange, onCheck) {
switch (msg.typeUrl) {
case "/cosmos.bank.v1beta1.MsgSend":
return <MsgSend msg={msg} onMsgChange={onMsgChange} onCheck={onCheck} />;
case "/cosmos.staking.v1beta1.MsgDelegate":
return <MsgDelegate msg={msg} onMsgChange={onMsgChange} onCheck={onCheck} />;
case "/cosmos.staking.v1beta1.MsgUndelegate":
Expand Down
19 changes: 10 additions & 9 deletions components/messages/MsgSend.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ const MsgDelegate = (props) => {

const v = msg.value;
if (!v.amount) return false;
if (!v.amount.denom) return false;
if (!v.amount.amount) return false;
if (!v.amount[0]) return false;
if (!v.amount[0].denom) return false;
if (!v.amount[0].amount) return false;

const _fromAddressError = checkAddress(v.delegatorAddress, state.chain.addressPrefix);
const _fromAddressError = checkAddress(v.fromAddress, state.chain.addressPrefix);
if (updateInternalErrors) {
if (_fromAddressError) {
const errorMsg = `Invalid from address for network ${state.chain.chainId}: ${_fromAddressError}`;
Expand All @@ -31,7 +32,7 @@ const MsgDelegate = (props) => {
setFromAddressError("");
}
}
const _toAddressError = checkAddress(v.validatorAddress, state.chain.addressPrefix);
const _toAddressError = checkAddress(v.toAddress, state.chain.addressPrefix);
if (updateInternalErrors) {
if (_toAddressError) {
const errorMsg = `Invalid to address for network ${state.chain.chainId}: ${_toAddressError}`;
Expand All @@ -49,14 +50,14 @@ const MsgDelegate = (props) => {

function checkAndSetAmount(newAmount) {
const newMsg = JSON.parse(JSON.stringify(props.msg));
newMsg.value.amount.amount = newAmount;
newMsg.value.amount[0].amount = newAmount;
onMsgChange(newMsg);
onCheck(checkMsg(newMsg, true));
}

function checkAndSetToAddress(valaddr) {
function checkAndSetToAddress(toaddr) {
const newMsg = JSON.parse(JSON.stringify(props.msg));
newMsg.value.validatorAddress = valaddr;
newMsg.value.toAddress = toaddr;
onMsgChange(newMsg);
onCheck(checkMsg(newMsg, true));
}
Expand Down Expand Up @@ -89,10 +90,10 @@ const MsgDelegate = (props) => {
</div>
<div className="form-item">
<Input
label={`Amount (${props.msg.value.amount.denom})`}
label={`Amount (${props.msg.value.amount[0].denom})`}
name="amount"
type="number"
value={props.msg.value.amount.amount}
value={props.msg.value.amount[0].amount}
onChange={(e) => checkAndSetAmount(e.target.value)}
/>
</div>
Expand Down

0 comments on commit ffbc0d2

Please sign in to comment.