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

Add cosmwasm msgs #158

Merged
merged 48 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
a272a3c
Add missing dep
abefernan Jul 10, 2023
02b4f74
Add new types
abefernan Jul 10, 2023
0327a36
Add execute details
abefernan Jul 10, 2023
630156c
Add execute form
abefernan Jul 10, 2023
910726f
Add instantiate details
abefernan Jul 10, 2023
19ad69e
Add instantiate form
abefernan Jul 10, 2023
8e8cb71
Add instantiate2 details
abefernan Jul 10, 2023
b3076b6
Add instantiate2 form
abefernan Jul 10, 2023
8ffb2a7
Switch new forms and details
abefernan Jul 10, 2023
9d46c88
Fix typos
abefernan Jul 10, 2023
97d8c56
Fix remove error
abefernan Jul 10, 2023
7ebb8f3
Add migrate types
abefernan Jul 10, 2023
3d4f9de
Add migrate details
abefernan Jul 10, 2023
fad870c
Add migrate form
abefernan Jul 10, 2023
cc1fbc2
Merge branch 'master' into feat/add-cw-msgs
abefernan Jul 11, 2023
c60c395
Adapt to useChains hook
abefernan Jul 11, 2023
726bde7
Add jsoneditor dep
abefernan Jul 13, 2023
a8acfa4
Add JsonEditor component
abefernan Jul 13, 2023
089383a
Use JsonEditor in MsgExecuteContractForm
abefernan Jul 13, 2023
edc1c61
Use JsonEditor in MsgInstantiateContractForm
abefernan Jul 13, 2023
1185857
Use JsonEditor in MsgInstantiateContract2Form
abefernan Jul 13, 2023
fd60bd5
Remove unneded dep from useEffect
abefernan Jul 13, 2023
5cc4d50
Use JsonEditor in MsgMigrateContractForm
abefernan Jul 13, 2023
5bee548
Remove "any" type. Use Mode type
abefernan Jul 13, 2023
eb02c72
Use lossy option
abefernan Jul 14, 2023
70366ab
Use readonly JsonEditor to view msgs
abefernan Jul 14, 2023
ff805e3
Format msg properly for sending
abefernan Jul 14, 2023
fa77bc3
Add label validation to instantiate
abefernan Jul 14, 2023
7a3d341
Set options in signing client
abefernan Jul 14, 2023
7d261f5
Merge branch 'master' into feat/add-cw-msgs
abefernan Jul 14, 2023
b0a3483
Add macroCoinToMicroCoin helper
abefernan Jul 20, 2023
379b993
Add tests for macroCoinToMicroCoin
abefernan Jul 20, 2023
bb1f131
Fix ChainInfo type import
abefernan Jul 20, 2023
7cc9818
Use macroCoinToMicroCoin in MsgSend and CW msgs
abefernan Jul 20, 2023
37beb3d
Use lockfile v3 with node 18 and npm 9
abefernan Jul 20, 2023
33c874a
Merge branch 'master' into feat/add-cw-msgs
abefernan Jul 20, 2023
2a1b6e8
Add amount checks back to instantiate msgs
abefernan Jul 21, 2023
4fe6d79
Reorder form fields for migrate
abefernan Jul 21, 2023
3bae106
Update cosmjs
abefernan Jul 21, 2023
3c63c41
Merge branch 'master' into feat/add-cw-msgs
abefernan Jul 26, 2023
5c6bf37
Update lockfile
abefernan Jul 26, 2023
0f71ff5
Remove fix msg from details
abefernan Jul 26, 2023
faa7a24
Use salt as hex
abefernan Jul 26, 2023
3d8e462
Add parseError instead of lossy
abefernan Jul 26, 2023
f62fa05
Return undefined msgContentUtf8Array
abefernan Jul 26, 2023
d6c1686
Remove fix msg. Use hex salt
abefernan Jul 26, 2023
d49baa2
Check empty salt
abefernan Jul 26, 2023
62be9d6
Avoid sending form with JSON errors
abefernan Jul 27, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { fromUtf8 } from "@cosmjs/encoding";
import { MsgExecuteContract } from "cosmjs-types/cosmwasm/wasm/v1/tx";
import dynamic from "next/dynamic";
import { useChains } from "../../../context/ChainsContext";
import { printableCoins } from "../../../lib/displayHelpers";
import HashView from "../HashView";

const JsonEditor = dynamic(() => import("../../inputs/JsonEditor"), { ssr: false });

interface TxMsgExecuteContractDetailsProps {
readonly msgValue: MsgExecuteContract;
}

const TxMsgExecuteContractDetails = ({ msgValue }: TxMsgExecuteContractDetailsProps) => {
const { chain } = useChains();

return (
<>
<li>
<h3>MsgExecuteContract</h3>
</li>
<li>
<label>Contract:</label>
<div title={msgValue.contract}>
<HashView hash={msgValue.contract} />
</div>
</li>
<li>
<label>Funds:</label>
<div>{printableCoins(msgValue.funds, chain)}</div>
</li>
<li>
<JsonEditor readOnly content={{ json: JSON.parse(fromUtf8(msgValue.msg, true)) }} />
Copy link
Member

Choose a reason for hiding this comment

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

What's the reason for using lossy mode (true) here? I think if the contents of the variable is not valid UTF-8, something went wrong and we should throw.

</li>
<style jsx>{`
li:not(:has(h3)) {
background: rgba(255, 255, 255, 0.03);
padding: 6px 10px;
border-radius: 8px;
display: flex;
align-items: center;
}
li + li:nth-child(2) {
margin-top: 25px;
}
li + li {
margin-top: 10px;
}
li div {
padding: 3px 6px;
}
label {
font-size: 12px;
background: rgba(255, 255, 255, 0.1);
padding: 3px 6px;
border-radius: 5px;
display: block;
}
`}</style>
</>
);
};

export default TxMsgExecuteContractDetails;
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { fromUtf8 } from "@cosmjs/encoding";
import { MsgInstantiateContract2 } from "cosmjs-types/cosmwasm/wasm/v1/tx";
import dynamic from "next/dynamic";
import { useChains } from "../../../context/ChainsContext";
import { printableCoins } from "../../../lib/displayHelpers";
import HashView from "../HashView";

const JsonEditor = dynamic(() => import("../../inputs/JsonEditor"), { ssr: false });

interface TxMsgInstantiateContract2DetailsProps {
readonly msgValue: MsgInstantiateContract2;
}

const TxMsgInstantiateContract2Details = ({ msgValue }: TxMsgInstantiateContract2DetailsProps) => {
const { chain } = useChains();

return (
<>
<li>
<h3>MsgInstantiateContract2</h3>
</li>
<li>
<label>Code ID:</label>
<div>{msgValue.codeId.toString()}</div>
</li>
<li>
<label>Label:</label>
<div>{msgValue.label || "None"}</div>
</li>
<li>
<label>Admin:</label>
{msgValue.admin ? (
<div title={msgValue.admin}>
<HashView hash={msgValue.admin} />
</div>
) : (
<div>None</div>
)}
</li>
<li>
<label>Fix msg:</label>
<div>{msgValue.fixMsg ? "Yes" : "No"}</div>
</li>
<li>
<label>Salt:</label>
<div>{fromUtf8(msgValue.salt, true)}</div>
Copy link
Member

Choose a reason for hiding this comment

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

This might be non-printable. I'd show it as hex.

Suggested change
<div>{fromUtf8(msgValue.salt, true)}</div>
<div>{toHex(msgValue.salt)}</div>

</li>
<li>
<label>Funds:</label>
<div>{printableCoins(msgValue.funds, chain)}</div>
</li>
<li>
<JsonEditor readOnly content={{ json: JSON.parse(fromUtf8(msgValue.msg, true)) }} />
</li>
<style jsx>{`
li:not(:has(h3)) {
background: rgba(255, 255, 255, 0.03);
padding: 6px 10px;
border-radius: 8px;
display: flex;
align-items: center;
}
li + li:nth-child(2) {
margin-top: 25px;
}
li + li {
margin-top: 10px;
}
li div {
padding: 3px 6px;
}
label {
font-size: 12px;
background: rgba(255, 255, 255, 0.1);
padding: 3px 6px;
border-radius: 5px;
display: block;
}
`}</style>
</>
);
};

export default TxMsgInstantiateContract2Details;
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { fromUtf8 } from "@cosmjs/encoding";
import { MsgInstantiateContract } from "cosmjs-types/cosmwasm/wasm/v1/tx";
import dynamic from "next/dynamic";
import { useChains } from "../../../context/ChainsContext";
import { printableCoins } from "../../../lib/displayHelpers";
import HashView from "../HashView";

const JsonEditor = dynamic(() => import("../../inputs/JsonEditor"), { ssr: false });

interface TxMsgInstantiateContractDetailsProps {
readonly msgValue: MsgInstantiateContract;
}

const TxMsgInstantiateContractDetails = ({ msgValue }: TxMsgInstantiateContractDetailsProps) => {
const { chain } = useChains();

return (
<>
<li>
<h3>MsgInstantiateContract</h3>
</li>
<li>
<label>Code ID:</label>
<div>{msgValue.codeId.toString()}</div>
</li>
<li>
<label>Label:</label>
<div>{msgValue.label || "None"}</div>
</li>
<li>
<label>Admin:</label>
{msgValue.admin ? (
<div title={msgValue.admin}>
<HashView hash={msgValue.admin} />
</div>
) : (
<div>None</div>
)}
</li>
<li>
<label>Funds:</label>
<div>{printableCoins(msgValue.funds, chain)}</div>
</li>
<li>
<JsonEditor readOnly content={{ json: JSON.parse(fromUtf8(msgValue.msg, true)) }} />
</li>
<style jsx>{`
li:not(:has(h3)) {
background: rgba(255, 255, 255, 0.03);
padding: 6px 10px;
border-radius: 8px;
display: flex;
align-items: center;
}
li + li:nth-child(2) {
margin-top: 25px;
}
li + li {
margin-top: 10px;
}
li div {
padding: 3px 6px;
}
label {
font-size: 12px;
background: rgba(255, 255, 255, 0.1);
padding: 3px 6px;
border-radius: 5px;
display: block;
}
`}</style>
</>
);
};

export default TxMsgInstantiateContractDetails;
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { fromUtf8 } from "@cosmjs/encoding";
import { MsgMigrateContract } from "cosmjs-types/cosmwasm/wasm/v1/tx";
import dynamic from "next/dynamic";
import HashView from "../HashView";

const JsonEditor = dynamic(() => import("../../inputs/JsonEditor"), { ssr: false });

interface TxMsgMigrateContractDetailsProps {
readonly msgValue: MsgMigrateContract;
}

const TxMsgMigrateContractDetails = ({ msgValue }: TxMsgMigrateContractDetailsProps) => (
<>
<li>
<h3>MsgMigrateContract</h3>
</li>
<li>
<label>Contract:</label>
<div title={msgValue.contract}>
<HashView hash={msgValue.contract} />
</div>
</li>
<li>
<label>Code ID:</label>
<div>{msgValue.codeId.toString()}</div>
</li>
<li>
<JsonEditor readOnly content={{ json: JSON.parse(fromUtf8(msgValue.msg, true)) }} />
</li>
<style jsx>{`
li:not(:has(h3)) {
background: rgba(255, 255, 255, 0.03);
padding: 6px 10px;
border-radius: 8px;
display: flex;
align-items: center;
}
li + li:nth-child(2) {
margin-top: 25px;
}
li + li {
margin-top: 10px;
}
li div {
padding: 3px 6px;
}
label {
font-size: 12px;
background: rgba(255, 255, 255, 0.1);
padding: 3px 6px;
border-radius: 5px;
display: block;
}
`}</style>
</>
);

export default TxMsgMigrateContractDetails;
12 changes: 12 additions & 0 deletions components/dataViews/TransactionInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import StackableContainer from "../../layout/StackableContainer";
import TxMsgClaimRewardsDetails from "./TxMsgClaimRewardsDetails";
import TxMsgCreateVestingAccountDetails from "./TxMsgCreateVestingAccountDetails";
import TxMsgDelegateDetails from "./TxMsgDelegateDetails";
import TxMsgExecuteContractDetails from "./TxMsgExecuteContractDetails";
import TxMsgInstantiateContract2Details from "./TxMsgInstantiateContract2Details";
import TxMsgInstantiateContractDetails from "./TxMsgInstantiateContractDetails";
import TxMsgMigrateContractDetails from "./TxMsgMigrateContractDetails";
import TxMsgRedelegateDetails from "./TxMsgRedelegateDetails";
import TxMsgSendDetails from "./TxMsgSendDetails";
import TxMsgSetWithdrawAddressDetails from "./TxMsgSetWithdrawAddressDetails";
Expand All @@ -31,6 +35,14 @@ const TxMsgDetails = ({ typeUrl, value: msgValue }: EncodeObject) => {
return <TxMsgCreateVestingAccountDetails msgValue={msgValue} />;
case MsgTypeUrls.Transfer:
return <TxMsgTransferDetails msgValue={msgValue} />;
case MsgTypeUrls.Execute:
return <TxMsgExecuteContractDetails msgValue={msgValue} />;
case MsgTypeUrls.Instantiate:
return <TxMsgInstantiateContractDetails msgValue={msgValue} />;
case MsgTypeUrls.Instantiate2:
return <TxMsgInstantiateContract2Details msgValue={msgValue} />;
case MsgTypeUrls.Migrate:
return <TxMsgMigrateContractDetails msgValue={msgValue} />;
default:
return null;
}
Expand Down
Loading