launchpad-ledger: Add MsgSend to demo

This commit is contained in:
willclarktech 2020-09-15 11:51:17 +02:00
parent 4b9b40f69b
commit e89c456634
No known key found for this signature in database
GPG Key ID: 551A86E2E398ADF7
3 changed files with 29 additions and 13 deletions

View File

@ -20,5 +20,5 @@ input {
textarea {
width: 32em;
height: 14em;
height: 28em;
}

View File

@ -31,17 +31,6 @@
<div>
<label>Message</label>
<textarea id="message">
{
"account_number": 0,
"chain_id": "testing",
"fee": {
"amount": [{ "amount": 100, "denom": "ucosm" }],
"gas": 250
},
"memo": "Some memo",
"msgs": [],
"sequence": 0
}
</textarea>
</div>
<div>

View File

@ -5,18 +5,45 @@ import { LedgerSigner } from "../ledgersigner";
declare const window: any;
declare const document: any;
function createMessage(address: string): string {
return `{
"account_number": 0,
"chain_id": "testing",
"fee": {
"amount": [{ "amount": 100, "denom": "ucosm" }],
"gas": 250
},
"memo": "Some memo",
"msgs": [{
"type": "cosmos-sdk/MsgSend",
"value": {
"amount": [{
"amount": "1234567",
"denom": "ucosm"
}],
"from_address": "${address}",
"to_address": "${address}"
}
}],
"sequence": 0
}`;
}
const signer = new LedgerSigner({ testModeAllowed: true });
window.getAccounts = async function getAccounts(): Promise<void> {
const addressInput = document.getElementById("address");
const accountsDiv = document.getElementById("accounts");
const messageTextArea = document.getElementById("message");
accountsDiv.textContent = "Loading...";
try {
const accounts = await signer.getAccounts();
const prettyAccounts = accounts.map((account) => ({ ...account, pubkey: toHex(account.pubkey) }));
accountsDiv.textContent = JSON.stringify(prettyAccounts, null, "\t");
addressInput.value = accounts[0].address;
const address = accounts[0].address;
addressInput.value = address;
messageTextArea.textContent = createMessage(address);
} catch (error) {
accountsDiv.textContent = error;
}