@mictonode/widget 0.3.16 → 0.3.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/FUNDING.yml +3 -3
- package/.github/workflows/npm-publish.yml +34 -34
- package/.prettierrc.json +9 -9
- package/.vscode/extensions.json +3 -3
- package/LICENSE +674 -674
- package/README.md +41 -41
- package/dist/{main-d0e5d1e4.js → main-465ae991.js} +151 -149
- package/dist/ping-widget.js +2 -2
- package/dist/ping-widget.umd.cjs +17 -17
- package/dist/{query.lcd-3d4d3495.js → query.lcd-d9c6163c.js} +1 -1
- package/dist/{query.rpc.Query-b7807c29.js → query.rpc.Query-a479e6f9.js} +1 -1
- package/dist/{tx.rpc.msg-59c3408a.js → tx.rpc.msg-7444045d.js} +1 -1
- package/example/.vscode/extensions.json +3 -3
- package/example/README.md +7 -7
- package/example/index.html +12 -12
- package/example/package.json +19 -19
- package/example/pnpm-lock.yaml +465 -465
- package/example/public/cdn.html +19 -19
- package/example/src/App.vue +73 -73
- package/example/src/main.js +4 -4
- package/example/vite.config.js +7 -7
- package/index.html +12 -12
- package/lib/components/ConnectWallet/index.vue +262 -262
- package/lib/components/TokenConvert/index.vue +1033 -1033
- package/lib/components/TokenConvert/tokens.ts +36 -36
- package/lib/components/TxDialog/index.vue +8 -8
- package/lib/components/TxDialog/messages/Delegate.vue +174 -174
- package/lib/components/TxDialog/messages/Deposit.vue +96 -96
- package/lib/components/TxDialog/messages/Redelegate.vue +160 -160
- package/lib/components/TxDialog/messages/Send.vue +142 -142
- package/lib/components/TxDialog/messages/Transfer.vue +248 -248
- package/lib/components/TxDialog/messages/Unbond.vue +103 -103
- package/lib/components/TxDialog/messages/Vote.vue +62 -62
- package/lib/components/TxDialog/messages/Withdraw.vue +55 -55
- package/lib/components/TxDialog/messages/WithdrawCommission.vue +74 -74
- package/lib/components/TxDialog/wasm/ClearAdmin.vue +55 -55
- package/lib/components/TxDialog/wasm/ExecuteContract.vue +98 -98
- package/lib/components/TxDialog/wasm/InstantiateContract.vue +108 -108
- package/lib/components/TxDialog/wasm/MigrateContract.vue +76 -76
- package/lib/components/TxDialog/wasm/MigrateContract2.vue +76 -76
- package/lib/components/TxDialog/wasm/StoreCode.vue +100 -100
- package/lib/components/TxDialog/wasm/UpdateAdmin.vue +74 -74
- package/lib/main.css +132 -7
- package/lib/main.ts +23 -23
- package/lib/utils/TokenUnitConverter.ts +44 -44
- package/lib/utils/format.ts +16 -16
- package/lib/utils/http.ts +154 -154
- package/lib/utils/type.ts +56 -56
- package/lib/wallet/EthermintMessageAdapter.ts +135 -135
- package/lib/wallet/UniClient.ts +144 -144
- package/lib/wallet/Wallet.ts +142 -142
- package/lib/wallet/wallets/KeplerWallet.ts +141 -141
- package/lib/wallet/wallets/LeapWallet.ts +141 -141
- package/lib/wallet/wallets/LedgerWallet.ts +202 -202
- package/lib/wallet/wallets/MetamaskSnapWallet.ts +105 -105
- package/lib/wallet/wallets/MetamaskWallet.ts +173 -173
- package/lib/wallet/wallets/OKXWallet.ts +202 -202
- package/lib/wallet/wallets/UnisatWallet.ts +198 -198
- package/package.json +3 -3
- package/postcss.config.js +6 -6
- package/src/App.vue +225 -225
- package/src/main.ts +7 -4
- package/src/styles/design-system.css +150 -0
- package/src/vite-env.d.ts +1 -1
- package/tailwind.config.js +211 -34
- package/tsconfig.json +25 -25
- package/tsconfig.node.json +10 -10
- package/vite.config.ts +62 -62
- package/vue-shim.d.ts +6 -6
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import { PropType, computed, onMounted, ref } from 'vue';
|
|
3
|
-
import { Coin, CoinMetadata } from '../../../utils/type';
|
|
4
|
-
import { getStakingParam } from '../../../utils/http';
|
|
5
|
-
import { TokenUnitConverter } from '../../../utils/TokenUnitConverter';
|
|
6
|
-
|
|
7
|
-
const props = defineProps({
|
|
8
|
-
endpoint: {type: String, required: true },
|
|
9
|
-
sender: {type: String, required: true},
|
|
10
|
-
balances: Object as PropType<Coin[]>,
|
|
11
|
-
metadata: Object as PropType<Record<string, CoinMetadata>>,
|
|
12
|
-
params: String,
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
const params = computed(() => JSON.parse(props.params || "{}"))
|
|
16
|
-
const denom = ref("")
|
|
17
|
-
const amount = ref("")
|
|
18
|
-
const amountDenom = ref("")
|
|
19
|
-
|
|
20
|
-
const available = computed(() => {
|
|
21
|
-
const convert = new TokenUnitConverter(props.metadata)
|
|
22
|
-
const base = props.balances?.find(x => x.denom === denom.value) || { amount: "0", denom: denom.value }
|
|
23
|
-
return {
|
|
24
|
-
base,
|
|
25
|
-
display: convert.baseToUnit(base, amountDenom.value)
|
|
26
|
-
}
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
const msgs = computed(() => {
|
|
30
|
-
const convert = new TokenUnitConverter(props.metadata)
|
|
31
|
-
return [{
|
|
32
|
-
typeUrl: '/cosmos.gov.v1beta1.MsgDeposit',
|
|
33
|
-
value: {
|
|
34
|
-
depositor: props.sender,
|
|
35
|
-
proposalId: params.value.proposal_id,
|
|
36
|
-
amount: [convert.displayToBase(denom.value, {
|
|
37
|
-
amount: String(amount.value),
|
|
38
|
-
denom: amountDenom.value
|
|
39
|
-
})],
|
|
40
|
-
},
|
|
41
|
-
}]
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
const units = computed(() => {
|
|
45
|
-
if(!props.metadata || !props.metadata[denom.value]) {
|
|
46
|
-
amountDenom.value = denom.value
|
|
47
|
-
return [{denom: denom.value, exponent: 0, aliases: []}]
|
|
48
|
-
}
|
|
49
|
-
const list = props.metadata[denom.value].denom_units.sort((a, b) => b.exponent - a.exponent)
|
|
50
|
-
if(list.length > 0) amountDenom.value = list[0].denom
|
|
51
|
-
return list
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
const isValid = computed(() => {
|
|
55
|
-
let ok = true
|
|
56
|
-
let error = ""
|
|
57
|
-
if(!params.value.proposal_id) {
|
|
58
|
-
ok = false
|
|
59
|
-
error = "Proposal id is empty"
|
|
60
|
-
}
|
|
61
|
-
if(!(Number(amount.value) > 0)) {
|
|
62
|
-
ok = false
|
|
63
|
-
error = "Amount should be great than 0"
|
|
64
|
-
}
|
|
65
|
-
return { ok, error }
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
function initial() {
|
|
69
|
-
getStakingParam(props.endpoint).then(x => {
|
|
70
|
-
denom.value = x.params.bond_denom
|
|
71
|
-
})
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
defineExpose({msgs, isValid, initial})
|
|
75
|
-
</script>
|
|
76
|
-
<template>
|
|
77
|
-
<div>
|
|
78
|
-
<div class="form-control">
|
|
79
|
-
<label class="label">
|
|
80
|
-
<span class="label-text">Sender</span>
|
|
81
|
-
</label>
|
|
82
|
-
<input :value="sender" type="text" class="text-gray-600 dark:text-white input border !border-gray-300 dark:!border-
|
|
83
|
-
</div>
|
|
84
|
-
<div class="form-control">
|
|
85
|
-
<label class="label">
|
|
86
|
-
<span class="label-text">Amount</span>
|
|
87
|
-
<span>{{ available?.display.amount }}{{ available?.display.denom }}</span>
|
|
88
|
-
</label>
|
|
89
|
-
<label class="input-group">
|
|
90
|
-
<input v-model="amount" type="number" :placeholder="`Available: ${available?.display.amount}`" class="input border border-gray-300 dark:border-
|
|
91
|
-
<select v-model="amountDenom" class="select select-bordered dark:border-
|
|
92
|
-
<option v-for="u in units">{{ u.denom }}</option>
|
|
93
|
-
</select>
|
|
94
|
-
</label>
|
|
95
|
-
</div>
|
|
96
|
-
</div>
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { PropType, computed, onMounted, ref } from 'vue';
|
|
3
|
+
import { Coin, CoinMetadata } from '../../../utils/type';
|
|
4
|
+
import { getStakingParam } from '../../../utils/http';
|
|
5
|
+
import { TokenUnitConverter } from '../../../utils/TokenUnitConverter';
|
|
6
|
+
|
|
7
|
+
const props = defineProps({
|
|
8
|
+
endpoint: {type: String, required: true },
|
|
9
|
+
sender: {type: String, required: true},
|
|
10
|
+
balances: Object as PropType<Coin[]>,
|
|
11
|
+
metadata: Object as PropType<Record<string, CoinMetadata>>,
|
|
12
|
+
params: String,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
const params = computed(() => JSON.parse(props.params || "{}"))
|
|
16
|
+
const denom = ref("")
|
|
17
|
+
const amount = ref("")
|
|
18
|
+
const amountDenom = ref("")
|
|
19
|
+
|
|
20
|
+
const available = computed(() => {
|
|
21
|
+
const convert = new TokenUnitConverter(props.metadata)
|
|
22
|
+
const base = props.balances?.find(x => x.denom === denom.value) || { amount: "0", denom: denom.value }
|
|
23
|
+
return {
|
|
24
|
+
base,
|
|
25
|
+
display: convert.baseToUnit(base, amountDenom.value)
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
const msgs = computed(() => {
|
|
30
|
+
const convert = new TokenUnitConverter(props.metadata)
|
|
31
|
+
return [{
|
|
32
|
+
typeUrl: '/cosmos.gov.v1beta1.MsgDeposit',
|
|
33
|
+
value: {
|
|
34
|
+
depositor: props.sender,
|
|
35
|
+
proposalId: params.value.proposal_id,
|
|
36
|
+
amount: [convert.displayToBase(denom.value, {
|
|
37
|
+
amount: String(amount.value),
|
|
38
|
+
denom: amountDenom.value
|
|
39
|
+
})],
|
|
40
|
+
},
|
|
41
|
+
}]
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const units = computed(() => {
|
|
45
|
+
if(!props.metadata || !props.metadata[denom.value]) {
|
|
46
|
+
amountDenom.value = denom.value
|
|
47
|
+
return [{denom: denom.value, exponent: 0, aliases: []}]
|
|
48
|
+
}
|
|
49
|
+
const list = props.metadata[denom.value].denom_units.sort((a, b) => b.exponent - a.exponent)
|
|
50
|
+
if(list.length > 0) amountDenom.value = list[0].denom
|
|
51
|
+
return list
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
const isValid = computed(() => {
|
|
55
|
+
let ok = true
|
|
56
|
+
let error = ""
|
|
57
|
+
if(!params.value.proposal_id) {
|
|
58
|
+
ok = false
|
|
59
|
+
error = "Proposal id is empty"
|
|
60
|
+
}
|
|
61
|
+
if(!(Number(amount.value) > 0)) {
|
|
62
|
+
ok = false
|
|
63
|
+
error = "Amount should be great than 0"
|
|
64
|
+
}
|
|
65
|
+
return { ok, error }
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
function initial() {
|
|
69
|
+
getStakingParam(props.endpoint).then(x => {
|
|
70
|
+
denom.value = x.params.bond_denom
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
defineExpose({msgs, isValid, initial})
|
|
75
|
+
</script>
|
|
76
|
+
<template>
|
|
77
|
+
<div>
|
|
78
|
+
<div class="form-control">
|
|
79
|
+
<label class="label">
|
|
80
|
+
<span class="label-text">Sender</span>
|
|
81
|
+
</label>
|
|
82
|
+
<input :value="sender" type="text" class="text-gray-600 dark:text-white input border !border-gray-300 dark:!border-neutral-700" />
|
|
83
|
+
</div>
|
|
84
|
+
<div class="form-control">
|
|
85
|
+
<label class="label">
|
|
86
|
+
<span class="label-text">Amount</span>
|
|
87
|
+
<span>{{ available?.display.amount }}{{ available?.display.denom }}</span>
|
|
88
|
+
</label>
|
|
89
|
+
<label class="input-group">
|
|
90
|
+
<input v-model="amount" type="number" :placeholder="`Available: ${available?.display.amount}`" class="input border border-gray-300 dark:border-neutral-700 w-full dark:text-white" />
|
|
91
|
+
<select v-model="amountDenom" class="select select-bordered dark:border-neutral-700 dark:text-white">
|
|
92
|
+
<option v-for="u in units">{{ u.denom }}</option>
|
|
93
|
+
</select>
|
|
94
|
+
</label>
|
|
95
|
+
</div>
|
|
96
|
+
</div>
|
|
97
97
|
</template>
|
|
@@ -1,161 +1,161 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import { ComputedRef, PropType, computed, onMounted, ref } from 'vue';
|
|
3
|
-
import { getActiveValidators, getDelegations, getInactiveValidators, getStakingParam } from '../../../utils/http'
|
|
4
|
-
import { decimal2percent } from '../../../utils/format'
|
|
5
|
-
import { Coin, CoinMetadata } from '../../../utils/type';
|
|
6
|
-
import { TokenUnitConverter } from '../../../utils/TokenUnitConverter';
|
|
7
|
-
const props = defineProps({
|
|
8
|
-
endpoint: {type: String, required: true },
|
|
9
|
-
sender: {type: String, required: true},
|
|
10
|
-
balances: Object as PropType<Coin[]>,
|
|
11
|
-
metadata: Object as PropType<Record<string, CoinMetadata>>,
|
|
12
|
-
params: String,
|
|
13
|
-
});
|
|
14
|
-
const params = computed(() => JSON.parse(props.params || "{}"))
|
|
15
|
-
|
|
16
|
-
const validator = ref('')
|
|
17
|
-
|
|
18
|
-
const activeValidators = ref([])
|
|
19
|
-
const inactiveValidators = ref([])
|
|
20
|
-
const stakingDenom = ref("")
|
|
21
|
-
const amount = ref("")
|
|
22
|
-
const amountDenom = ref("")
|
|
23
|
-
const delegation = ref({} as Coin)
|
|
24
|
-
const error = ref("")
|
|
25
|
-
|
|
26
|
-
const sourceValidator = computed(() => {
|
|
27
|
-
// @ts-ignore
|
|
28
|
-
const v = activeValidators.value.find(v => v.operator_address === params.validator_address)
|
|
29
|
-
if(v) {
|
|
30
|
-
// @ts-ignore
|
|
31
|
-
return `${v.description.moniker} (${decimal2percent(v.commission.commission_rates.rate)}%)`
|
|
32
|
-
}
|
|
33
|
-
return params.value.validator_address
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
const msgs = computed(() => {
|
|
37
|
-
const convert = new TokenUnitConverter(props.metadata)
|
|
38
|
-
return [{
|
|
39
|
-
typeUrl: '/cosmos.staking.v1beta1.MsgBeginRedelegate',
|
|
40
|
-
value: {
|
|
41
|
-
delegatorAddress: props.sender,
|
|
42
|
-
validatorSrcAddress: params.value.validator_address,
|
|
43
|
-
validatorDstAddress: validator.value,
|
|
44
|
-
amount: convert.displayToBase(delegation.value.denom, {
|
|
45
|
-
amount: String(amount.value),
|
|
46
|
-
denom: amountDenom.value,
|
|
47
|
-
}),
|
|
48
|
-
},
|
|
49
|
-
}]
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
const list: ComputedRef<{
|
|
53
|
-
operator_address: string,
|
|
54
|
-
description: {moniker: string}
|
|
55
|
-
commission: { commission_rates: {rate: string}}
|
|
56
|
-
status: string
|
|
57
|
-
}[]> = computed(() => {
|
|
58
|
-
return [...activeValidators.value, ...inactiveValidators.value]
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
const available = computed(() => {
|
|
62
|
-
const convert = new TokenUnitConverter(props.metadata)
|
|
63
|
-
const base = delegation.value || { amount: "0", denom: stakingDenom.value }
|
|
64
|
-
return {
|
|
65
|
-
base,
|
|
66
|
-
display: convert.baseToUnit(base, amountDenom.value)
|
|
67
|
-
}
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
const units = computed(() => {
|
|
71
|
-
if(!props.metadata || !props.metadata[stakingDenom.value]) {
|
|
72
|
-
amountDenom.value = stakingDenom.value
|
|
73
|
-
return [{denom: stakingDenom.value, exponent: 0, aliases: []}]
|
|
74
|
-
}
|
|
75
|
-
const list = props.metadata[stakingDenom.value].denom_units.sort((a, b) => b.exponent - a.exponent)
|
|
76
|
-
if(list.length > 0) amountDenom.value = list[0].denom
|
|
77
|
-
return list
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
const isValid = computed(() => {
|
|
81
|
-
let ok = true
|
|
82
|
-
let error = ""
|
|
83
|
-
if(!validator.value) {
|
|
84
|
-
ok = false
|
|
85
|
-
error = "Validator is empty"
|
|
86
|
-
}
|
|
87
|
-
if(!validator.value) {
|
|
88
|
-
ok = false
|
|
89
|
-
error = "Validator is empty"
|
|
90
|
-
}
|
|
91
|
-
if(!(Number(amount.value) > 0)) {
|
|
92
|
-
ok = false
|
|
93
|
-
error = "Amount should be great than 0"
|
|
94
|
-
}
|
|
95
|
-
return { ok, error }
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
function initial() {
|
|
100
|
-
getDelegations(props.endpoint, params.value.validator_address, props.sender).then(x => {
|
|
101
|
-
delegation.value = x.delegation_response.balance
|
|
102
|
-
}).catch(err => {
|
|
103
|
-
error.value = err
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
getStakingParam(props.endpoint).then((x) => {
|
|
107
|
-
stakingDenom.value = x.params.bond_denom;
|
|
108
|
-
// unbondingTime.value = x.params.unbonding_time;
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
getActiveValidators(props.endpoint).then(x => {
|
|
112
|
-
activeValidators.value = x.validators
|
|
113
|
-
validator.value = x.validators.find(v => v.description.identity === '6783E9F948541962')?.operator_address
|
|
114
|
-
})
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
defineExpose({msgs, isValid, initial})
|
|
118
|
-
</script>
|
|
119
|
-
<template>
|
|
120
|
-
<div>
|
|
121
|
-
<div class="form-control">
|
|
122
|
-
<label class="label">
|
|
123
|
-
<span class="label-text">Sender</span>
|
|
124
|
-
</label>
|
|
125
|
-
<input :value="sender" type="text" class="text-gray-600 dark:text-white input border !border-gray-300 dark:!border-
|
|
126
|
-
</div>
|
|
127
|
-
<div class="form-control">
|
|
128
|
-
<label class="label">
|
|
129
|
-
<span class="label-text">Source Validator</span>
|
|
130
|
-
</label>
|
|
131
|
-
<input :value="sourceValidator" type="text" class="input border border-gray-300 dark:border-
|
|
132
|
-
</div>
|
|
133
|
-
<div class="form-control">
|
|
134
|
-
<label class="label">
|
|
135
|
-
<span class="label-text">Destination Validator</span>
|
|
136
|
-
</label>
|
|
137
|
-
<select v-model="validator" class="select select-bordered dark:border-
|
|
138
|
-
<option value="">Select a validator</option>
|
|
139
|
-
<option v-for="v in list" :value="v.operator_address">
|
|
140
|
-
{{ v.description.moniker }} ({{ decimal2percent(v.commission.commission_rates.rate) }}%)
|
|
141
|
-
<span v-if="v.status !== 'BOND_STATUS_BONDED'">x</span>
|
|
142
|
-
</option>
|
|
143
|
-
</select>
|
|
144
|
-
</div>
|
|
145
|
-
<div class="form-control">
|
|
146
|
-
<label class="label">
|
|
147
|
-
<span class="label-text">Amount</span>
|
|
148
|
-
<span>{{ available?.display.amount }}{{ available?.display.denom }}</span>
|
|
149
|
-
</label>
|
|
150
|
-
<label class="input-group">
|
|
151
|
-
<input v-model="amount" type="number" :placeholder="`Available: ${available?.display.amount}${available?.display.denom}`" class="input border border-gray-300 dark:border-
|
|
152
|
-
<select v-model="amountDenom" class="select select-bordered dark:border-
|
|
153
|
-
<option v-for="u in units">{{ u.denom }}</option>
|
|
154
|
-
</select>
|
|
155
|
-
</label>
|
|
156
|
-
</div>
|
|
157
|
-
<div class="text-error">
|
|
158
|
-
{{ error }}
|
|
159
|
-
</div>
|
|
160
|
-
</div>
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { ComputedRef, PropType, computed, onMounted, ref } from 'vue';
|
|
3
|
+
import { getActiveValidators, getDelegations, getInactiveValidators, getStakingParam } from '../../../utils/http'
|
|
4
|
+
import { decimal2percent } from '../../../utils/format'
|
|
5
|
+
import { Coin, CoinMetadata } from '../../../utils/type';
|
|
6
|
+
import { TokenUnitConverter } from '../../../utils/TokenUnitConverter';
|
|
7
|
+
const props = defineProps({
|
|
8
|
+
endpoint: {type: String, required: true },
|
|
9
|
+
sender: {type: String, required: true},
|
|
10
|
+
balances: Object as PropType<Coin[]>,
|
|
11
|
+
metadata: Object as PropType<Record<string, CoinMetadata>>,
|
|
12
|
+
params: String,
|
|
13
|
+
});
|
|
14
|
+
const params = computed(() => JSON.parse(props.params || "{}"))
|
|
15
|
+
|
|
16
|
+
const validator = ref('')
|
|
17
|
+
|
|
18
|
+
const activeValidators = ref([])
|
|
19
|
+
const inactiveValidators = ref([])
|
|
20
|
+
const stakingDenom = ref("")
|
|
21
|
+
const amount = ref("")
|
|
22
|
+
const amountDenom = ref("")
|
|
23
|
+
const delegation = ref({} as Coin)
|
|
24
|
+
const error = ref("")
|
|
25
|
+
|
|
26
|
+
const sourceValidator = computed(() => {
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
const v = activeValidators.value.find(v => v.operator_address === params.validator_address)
|
|
29
|
+
if(v) {
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
return `${v.description.moniker} (${decimal2percent(v.commission.commission_rates.rate)}%)`
|
|
32
|
+
}
|
|
33
|
+
return params.value.validator_address
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const msgs = computed(() => {
|
|
37
|
+
const convert = new TokenUnitConverter(props.metadata)
|
|
38
|
+
return [{
|
|
39
|
+
typeUrl: '/cosmos.staking.v1beta1.MsgBeginRedelegate',
|
|
40
|
+
value: {
|
|
41
|
+
delegatorAddress: props.sender,
|
|
42
|
+
validatorSrcAddress: params.value.validator_address,
|
|
43
|
+
validatorDstAddress: validator.value,
|
|
44
|
+
amount: convert.displayToBase(delegation.value.denom, {
|
|
45
|
+
amount: String(amount.value),
|
|
46
|
+
denom: amountDenom.value,
|
|
47
|
+
}),
|
|
48
|
+
},
|
|
49
|
+
}]
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
const list: ComputedRef<{
|
|
53
|
+
operator_address: string,
|
|
54
|
+
description: {moniker: string}
|
|
55
|
+
commission: { commission_rates: {rate: string}}
|
|
56
|
+
status: string
|
|
57
|
+
}[]> = computed(() => {
|
|
58
|
+
return [...activeValidators.value, ...inactiveValidators.value]
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
const available = computed(() => {
|
|
62
|
+
const convert = new TokenUnitConverter(props.metadata)
|
|
63
|
+
const base = delegation.value || { amount: "0", denom: stakingDenom.value }
|
|
64
|
+
return {
|
|
65
|
+
base,
|
|
66
|
+
display: convert.baseToUnit(base, amountDenom.value)
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
const units = computed(() => {
|
|
71
|
+
if(!props.metadata || !props.metadata[stakingDenom.value]) {
|
|
72
|
+
amountDenom.value = stakingDenom.value
|
|
73
|
+
return [{denom: stakingDenom.value, exponent: 0, aliases: []}]
|
|
74
|
+
}
|
|
75
|
+
const list = props.metadata[stakingDenom.value].denom_units.sort((a, b) => b.exponent - a.exponent)
|
|
76
|
+
if(list.length > 0) amountDenom.value = list[0].denom
|
|
77
|
+
return list
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
const isValid = computed(() => {
|
|
81
|
+
let ok = true
|
|
82
|
+
let error = ""
|
|
83
|
+
if(!validator.value) {
|
|
84
|
+
ok = false
|
|
85
|
+
error = "Validator is empty"
|
|
86
|
+
}
|
|
87
|
+
if(!validator.value) {
|
|
88
|
+
ok = false
|
|
89
|
+
error = "Validator is empty"
|
|
90
|
+
}
|
|
91
|
+
if(!(Number(amount.value) > 0)) {
|
|
92
|
+
ok = false
|
|
93
|
+
error = "Amount should be great than 0"
|
|
94
|
+
}
|
|
95
|
+
return { ok, error }
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
function initial() {
|
|
100
|
+
getDelegations(props.endpoint, params.value.validator_address, props.sender).then(x => {
|
|
101
|
+
delegation.value = x.delegation_response.balance
|
|
102
|
+
}).catch(err => {
|
|
103
|
+
error.value = err
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
getStakingParam(props.endpoint).then((x) => {
|
|
107
|
+
stakingDenom.value = x.params.bond_denom;
|
|
108
|
+
// unbondingTime.value = x.params.unbonding_time;
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
getActiveValidators(props.endpoint).then(x => {
|
|
112
|
+
activeValidators.value = x.validators
|
|
113
|
+
validator.value = x.validators.find(v => v.description.identity === '6783E9F948541962')?.operator_address
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
defineExpose({msgs, isValid, initial})
|
|
118
|
+
</script>
|
|
119
|
+
<template>
|
|
120
|
+
<div>
|
|
121
|
+
<div class="form-control">
|
|
122
|
+
<label class="label">
|
|
123
|
+
<span class="label-text">Sender</span>
|
|
124
|
+
</label>
|
|
125
|
+
<input :value="sender" type="text" class="text-gray-600 dark:text-white input border !border-gray-300 dark:!border-neutral-700" />
|
|
126
|
+
</div>
|
|
127
|
+
<div class="form-control">
|
|
128
|
+
<label class="label">
|
|
129
|
+
<span class="label-text">Source Validator</span>
|
|
130
|
+
</label>
|
|
131
|
+
<input :value="sourceValidator" type="text" class="input border border-gray-300 dark:border-neutral-700 dark:text-white" readonly/>
|
|
132
|
+
</div>
|
|
133
|
+
<div class="form-control">
|
|
134
|
+
<label class="label">
|
|
135
|
+
<span class="label-text">Destination Validator</span>
|
|
136
|
+
</label>
|
|
137
|
+
<select v-model="validator" class="select select-bordered dark:border-neutral-700 dark:text-white">
|
|
138
|
+
<option value="">Select a validator</option>
|
|
139
|
+
<option v-for="v in list" :value="v.operator_address">
|
|
140
|
+
{{ v.description.moniker }} ({{ decimal2percent(v.commission.commission_rates.rate) }}%)
|
|
141
|
+
<span v-if="v.status !== 'BOND_STATUS_BONDED'">x</span>
|
|
142
|
+
</option>
|
|
143
|
+
</select>
|
|
144
|
+
</div>
|
|
145
|
+
<div class="form-control">
|
|
146
|
+
<label class="label">
|
|
147
|
+
<span class="label-text">Amount</span>
|
|
148
|
+
<span>{{ available?.display.amount }}{{ available?.display.denom }}</span>
|
|
149
|
+
</label>
|
|
150
|
+
<label class="input-group">
|
|
151
|
+
<input v-model="amount" type="number" :placeholder="`Available: ${available?.display.amount}${available?.display.denom}`" class="input border border-gray-300 dark:border-neutral-700 w-full dark:text-white" />
|
|
152
|
+
<select v-model="amountDenom" class="select select-bordered dark:border-neutral-700 dark:text-white">
|
|
153
|
+
<option v-for="u in units">{{ u.denom }}</option>
|
|
154
|
+
</select>
|
|
155
|
+
</label>
|
|
156
|
+
</div>
|
|
157
|
+
<div class="text-error">
|
|
158
|
+
{{ error }}
|
|
159
|
+
</div>
|
|
160
|
+
</div>
|
|
161
161
|
</template>
|