diff --git a/src/libs/data/data.js b/src/libs/data/data.js index 5a476d55..5c353eba 100644 --- a/src/libs/data/data.js +++ b/src/libs/data/data.js @@ -1,11 +1,29 @@ import dayjs from 'dayjs' +import relativeTime from 'dayjs/plugin/relativeTime' import { Bech32, fromBase64, fromHex, toHex, } from '@cosmjs/encoding' import { sha256 } from '@cosmjs/crypto' -export function toDay(time) { - return dayjs(time).format('YYYY-MM-DD HH:mm') +dayjs.extend(relativeTime) + +export function toDay(time, format = 'long') { + if (format === 'long') { + return dayjs(time).format('YYYY-MM-DD HH:mm') + } + if (format === 'date') { + return dayjs(time).format('YYYY-MM-DD') + } + if (format === 'time') { + return dayjs(time).format('HH:mm:ss') + } + if (format === 'from') { + return dayjs(time).fromNow() + } + if (format === 'to') { + return dayjs(time).toNow() + } + return dayjs(time).format('YYYY-MM-DD HH:mm:ss') } export function percent(num) { diff --git a/src/libs/data/proposal.js b/src/libs/data/proposal.js index 71738f74..81654771 100644 --- a/src/libs/data/proposal.js +++ b/src/libs/data/proposal.js @@ -28,9 +28,9 @@ export default class Proposal { this.title = element.content.value.title this.description = element.content.value.description this.tally = new ProposalTally().init(element.final_tally_result, total) - this.submit_time = toDay(element.submit_time) - this.voting_end_time = toDay(element.voting_end_time) - this.voting_start_time = toDay(element.voting_start_time) + this.submit_time = toDay(element.submit_time, 'date') + this.voting_end_time = toDay(element.voting_end_time, 'date') + this.voting_start_time = toDay(element.voting_start_time, 'date') this.total_deposit = formatToken(element.total_deposit[0]) this.contents = element.content.value return this diff --git a/src/libs/data/stdtx.js b/src/libs/data/stdtx.js index de1b5831..233e896c 100644 --- a/src/libs/data/stdtx.js +++ b/src/libs/data/stdtx.js @@ -7,7 +7,7 @@ export default class StdTx { this.fee = [new Token()] this.gas = 0 this.memo = '' - this.messages = [] + this.messages = null this.signatures = [] this.timeout_height = 0 } diff --git a/src/libs/data/wrapstdtx.js b/src/libs/data/wrapstdtx.js index fa1aab1c..f973a98c 100644 --- a/src/libs/data/wrapstdtx.js +++ b/src/libs/data/wrapstdtx.js @@ -3,6 +3,7 @@ import StdTx from './stdtx' export default class WrapStdTx { constructor() { + this.std = true this.code = 0 this.txhash = '' this.data = '' @@ -19,14 +20,19 @@ export default class WrapStdTx { static create(element, version = '0.40') { const self = new WrapStdTx() if (compareVersions(version, '0.40') < 1) { - self.txhash = element.txhash - self.data = element.data - self.gas_used = element.gas_used - self.gas_wanted = element.gas_wanted - self.height = Number(element.height) - self.logs = element.logs - self.timestamp = element.timestamp - self.tx = StdTx.create(element.tx) + if (element.txhash) { + self.txhash = element.txhash + self.data = element.data + self.gas_used = element.gas_used + self.gas_wanted = element.gas_wanted + self.height = Number(element.height) + self.logs = element.logs + self.timestamp = element.timestamp + self.tx = StdTx.create(element.tx) + } else { + self.std = false + self.raw = element + } } else { self.code = element.tx_response.code self.txhash = element.tx_response.txhash diff --git a/src/views/Block.vue b/src/views/Block.vue index d74ee507..06421289 100644 --- a/src/views/Block.vue +++ b/src/views/Block.vue @@ -82,16 +82,18 @@ export default { this.$http.getBlockByHeight(height).then(res => { this.block = res const { txs } = res.block.data + if (txs === null) return const array = [] - for (let i = 0; i <= txs.length; i += 1) { + for (let i = 0; i < txs.length; i += 1) { + let tx = new Tx() try { const origin = decodeTxRaw(fromBase64(txs[i])) - const tx = Tx.create(origin) - tx.setHash(txs[i]) - array.push(tx) + tx = Tx.create(origin) } catch (e) { - // catch errors + // catch errors } + tx.setHash(txs[i]) + array.push(tx) } if (array.length > 0) this.txs = array }) diff --git a/src/views/Blocks.vue b/src/views/Blocks.vue index d9c27499..069ea6be 100644 --- a/src/views/Blocks.vue +++ b/src/views/Blocks.vue @@ -20,11 +20,11 @@