From 5de2c39d41c809c8030fc164f9a23c141b9cd5b0 Mon Sep 17 00:00:00 2001 From: liangping <18786721@qq.com> Date: Thu, 26 Aug 2021 21:50:56 +0800 Subject: [PATCH] add operations --- src/libs/data/data.js | 22 +- src/views/Governance.vue | 325 +++++++------- src/views/OperationDelegateComponent.vue | 470 ++++++++++++++++++++ src/views/OperationRedelegateComponent.vue | 485 +++++++++++++++++++++ src/views/OperationTransferComponent.vue | 29 +- src/views/OperationUnbondComponent.vue | 468 ++++++++++++++++++++ src/views/OperationVoteComponent.vue | 431 ++++++++++++++++++ src/views/OperationWithdrawComponent.vue | 25 +- src/views/Staking.vue | 124 +++--- src/views/StakingValidator.vue | 66 ++- src/views/UserAccountDetail.vue | 135 +++++- src/views/UserAccounts.vue | 1 - 12 files changed, 2288 insertions(+), 293 deletions(-) create mode 100644 src/views/OperationDelegateComponent.vue create mode 100644 src/views/OperationRedelegateComponent.vue create mode 100644 src/views/OperationUnbondComponent.vue create mode 100644 src/views/OperationVoteComponent.vue diff --git a/src/libs/data/data.js b/src/libs/data/data.js index 797a2c7a..ba64db8c 100644 --- a/src/libs/data/data.js +++ b/src/libs/data/data.js @@ -56,7 +56,6 @@ export async function signDirect(signer, signerAddress, messages, fee, memo, { a throw new Error('Failed to retrieve account from signer') } const { pubkey } = accountFromSigner - console.log('accout:', accountFromSigner, pubkey) const txBodyEncodeObject = { typeUrl: '/cosmos.tx.v1beta1.TxBody', value: { @@ -66,11 +65,8 @@ export async function signDirect(signer, signerAddress, messages, fee, memo, { a } const txBodyBytes = new Registry().encode(txBodyEncodeObject) const gasLimit = Uint53.fromString(String(fee.gas)) - console.log('account from signer: ', txBodyBytes, gasLimit) const authInfoBytes = makeAuthInfoBytes([pubkey], fee.amount, gasLimit, sequence) - console.log('authinfo: ', authInfoBytes, chainId, accountNumber) const signDoc = makeSignDoc(txBodyBytes, authInfoBytes, chainId, accountNumber) - console.log('signdoc: ', signDoc, signer) // const { signature, signed } = await signer.signDirect(signerAddress, signDoc) const signBytes = makeSignBytes(signDoc) const hashedMessage = sha256(signBytes) @@ -78,7 +74,6 @@ export async function signDirect(signer, signerAddress, messages, fee, memo, { a const signatureBytes = new Uint8Array([...signature.r(32), ...signature.s(32)]) const stdSignature = encodeSecp256k1Signature(pubkey, signatureBytes) - console.log('custom sign:', txBodyBytes, authInfoBytes, signDoc) return TxRaw.fromPartial({ bodyBytes: txBodyBytes, authInfoBytes, @@ -104,12 +99,12 @@ export async function sign(device, chainId, signerAddress, messages, fee, memo, throw new Error('Please install keplr extension') } await window.keplr.enable(chainId) - signer = window.getOfflineSignerOnlyAmino(chainId) + signer = window.getOfflineSigner(chainId) } // Ensure the address has some tokens to spend const client = await SigningStargateClient.offline(signer) - return client.signAmino(signerAddress, messages, fee, memo, signerData) + return client.sign(signerAddress, messages, fee, memo, signerData) // return signDirect(signer, signerAddress, messages, fee, memo, signerData) } @@ -137,6 +132,19 @@ export function getLocalAccounts() { return getLocalObject('accounts') } +export function getLocalTxHistory() { + return getLocalObject('txHistory') +} + +export function setLocalTxHistory(newTx) { + const txs = getLocalTxHistory() + if (txs) { + txs.push(newTx) + return localStorage.setItem('txHistory', JSON.stringify(txs)) + } + return localStorage.setItem('txHistory', JSON.stringify([newTx])) +} + export function toDuration(value) { return dayjs.duration(value).humanize() } diff --git a/src/views/Governance.vue b/src/views/Governance.vue index c764ed67..55320b9e 100644 --- a/src/views/Governance.vue +++ b/src/views/Governance.vue @@ -1,174 +1,183 @@ + diff --git a/src/views/OperationRedelegateComponent.vue b/src/views/OperationRedelegateComponent.vue new file mode 100644 index 00000000..13668886 --- /dev/null +++ b/src/views/OperationRedelegateComponent.vue @@ -0,0 +1,485 @@ + + + + diff --git a/src/views/OperationTransferComponent.vue b/src/views/OperationTransferComponent.vue index 91ba865b..de8d59f4 100644 --- a/src/views/OperationTransferComponent.vue +++ b/src/views/OperationTransferComponent.vue @@ -134,20 +134,19 @@ name="fee" > - - - + + - - {{ item.denom }} - - - + {{ item.denom }} + + + {{ errors[0] }} @@ -239,7 +238,7 @@ import { required, email, url, between, alpha, integer, password, min, digits, alphaDash, length, } from '@validations' import { - formatToken, getLocalAccounts, getLocalChains, sign, timeIn, + formatToken, getLocalAccounts, getLocalChains, setLocalTxHistory, sign, timeIn, } from '@/libs/data' import chainAPI from '@/libs/fetch' import { Cosmos } from '@cosmostation/cosmosjs' @@ -431,7 +430,7 @@ export default { ).then((bodyBytes, s) => { console.log('signed: ', bodyBytes, s) this.$http.broadcastTx(bodyBytes, this.selectedChain).then(res => { - console.log(res) + setLocalTxHistory({ op: 'send', hash: res.txhash, time: new Date() }) this.$bvModal.hide('transfer-window') this.$toast({ component: ToastificationContent, diff --git a/src/views/OperationUnbondComponent.vue b/src/views/OperationUnbondComponent.vue new file mode 100644 index 00000000..ed2d4769 --- /dev/null +++ b/src/views/OperationUnbondComponent.vue @@ -0,0 +1,468 @@ + + + + diff --git a/src/views/OperationVoteComponent.vue b/src/views/OperationVoteComponent.vue new file mode 100644 index 00000000..61ff934f --- /dev/null +++ b/src/views/OperationVoteComponent.vue @@ -0,0 +1,431 @@ + + + + + diff --git a/src/views/OperationWithdrawComponent.vue b/src/views/OperationWithdrawComponent.vue index 420357fa..67a506a7 100644 --- a/src/views/OperationWithdrawComponent.vue +++ b/src/views/OperationWithdrawComponent.vue @@ -48,20 +48,19 @@ name="fee" > - - - + + - - {{ item.denom }} - - - + {{ item.denom }} + + + {{ errors[0] }} diff --git a/src/views/Staking.vue b/src/views/Staking.vue index 32120891..143afb21 100644 --- a/src/views/Staking.vue +++ b/src/views/Staking.vue @@ -18,73 +18,74 @@ Validators {{ validators.length }}/{{ stakingParameters.max_validators }} - - - - - - - - + + + + + + + + + +