@mictonode/widget 0.3.16 → 0.3.18
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-bbea3e54.js} +155 -153
- package/dist/ping-widget.js +2 -2
- package/dist/ping-widget.umd.cjs +18 -18
- package/dist/{query.lcd-3d4d3495.js → query.lcd-88036522.js} +1 -1
- package/dist/{query.rpc.Query-b7807c29.js → query.rpc.Query-3a2b14f8.js} +1 -1
- package/dist/{tx.rpc.msg-59c3408a.js → tx.rpc.msg-39f0b824.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 +422 -422
- 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 +591 -7
- package/lib/main.ts +24 -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 +5 -6
- package/postcss.config.js +6 -6
- package/src/App.vue +225 -225
- package/src/main.ts +7 -4
- package/src/styles/design-system.css +184 -0
- package/src/vite-env.d.ts +1 -1
- package/tailwind.config.js +158 -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,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
|
|
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
|
|
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:
|
|
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
|
|
152
|
-
<select v-model="amountDenom" class="select select-bordered dark:
|
|
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" />
|
|
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 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: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 w-full dark:text-white" />
|
|
152
|
+
<select v-model="amountDenom" class="select select-bordered 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>
|
|
@@ -1,142 +1,142 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import { PropType, computed, onMounted, ref } from 'vue';
|
|
3
|
-
import {
|
|
4
|
-
getStakingParam,
|
|
5
|
-
} from '../../../utils/http';
|
|
6
|
-
import { Coin, CoinMetadata } from '../../../utils/type';
|
|
7
|
-
import { TokenUnitConverter } from '../../../utils/TokenUnitConverter';
|
|
8
|
-
const props = defineProps({
|
|
9
|
-
endpoint: { type: String, required: true },
|
|
10
|
-
sender: { type: String, required: true },
|
|
11
|
-
balances: Object as PropType<Coin[]>,
|
|
12
|
-
metadata: Object as PropType<Record<string, CoinMetadata>>,
|
|
13
|
-
params: String,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const amount = ref('');
|
|
17
|
-
const recipient = ref('');
|
|
18
|
-
const denom = ref('');
|
|
19
|
-
const amountDenom = ref('')
|
|
20
|
-
|
|
21
|
-
const msgs = computed(() => {
|
|
22
|
-
const convert = new TokenUnitConverter(props.metadata)
|
|
23
|
-
return [
|
|
24
|
-
{
|
|
25
|
-
typeUrl: '/cosmos.bank.v1beta1.MsgSend',
|
|
26
|
-
value: {
|
|
27
|
-
fromAddress: props.sender,
|
|
28
|
-
toAddress: recipient.value,
|
|
29
|
-
amount: [
|
|
30
|
-
convert.displayToBase(denom.value, {
|
|
31
|
-
amount: String(amount.value),
|
|
32
|
-
denom: amountDenom.value
|
|
33
|
-
})
|
|
34
|
-
],
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
];
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
const available = computed(() => {
|
|
41
|
-
const base = (
|
|
42
|
-
props.balances?.find((x) => x.denom === denom.value) || {
|
|
43
|
-
amount: '0',
|
|
44
|
-
denom: '-',
|
|
45
|
-
}
|
|
46
|
-
)
|
|
47
|
-
const convert = new TokenUnitConverter(props.metadata)
|
|
48
|
-
return {
|
|
49
|
-
base,
|
|
50
|
-
display: convert.baseToUnit(base, amountDenom.value)
|
|
51
|
-
};
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const showBalances = computed(() => {
|
|
55
|
-
const convert = new TokenUnitConverter(props.metadata)
|
|
56
|
-
return props.balances?.map(b => ({
|
|
57
|
-
base: b,
|
|
58
|
-
display: convert.baseToDisplay(b)
|
|
59
|
-
})) || []
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
const units = computed(() => {
|
|
63
|
-
if(!props.metadata || !props.metadata[denom.value]) {
|
|
64
|
-
amountDenom.value = denom.value
|
|
65
|
-
return [{denom: denom.value, exponent: 0, aliases: []}]
|
|
66
|
-
}
|
|
67
|
-
const list = props.metadata[denom.value].denom_units.sort((a, b) => b.exponent - a.exponent)
|
|
68
|
-
if(list.length > 0) amountDenom.value = list[0].denom
|
|
69
|
-
return list
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
const isValid = computed(() => {
|
|
73
|
-
let ok = true
|
|
74
|
-
let error = ""
|
|
75
|
-
if(!recipient.value) {
|
|
76
|
-
ok = false
|
|
77
|
-
error = "Recipient is empty"
|
|
78
|
-
}
|
|
79
|
-
if(!(Number(amount.value) > 0)) {
|
|
80
|
-
ok = false
|
|
81
|
-
error = "Amount should be great than 0"
|
|
82
|
-
}
|
|
83
|
-
return { ok, error }
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
function initial() {
|
|
88
|
-
denom.value = props.params?.fees?.denom || '';
|
|
89
|
-
// getStakingParam(props.endpoint).then((x) => {
|
|
90
|
-
// denom.value = x.params?.bond_denom;
|
|
91
|
-
// });
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function formatDenom(v: any) {
|
|
95
|
-
return String(v).substring(0, 10)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
defineExpose({msgs, isValid, initial})
|
|
99
|
-
</script>
|
|
100
|
-
<template>
|
|
101
|
-
<div class="dark:text-gray-400">
|
|
102
|
-
<div class="form-control">
|
|
103
|
-
<label class="label">
|
|
104
|
-
<span class="label-text">Sender</span>
|
|
105
|
-
</label>
|
|
106
|
-
<input :value="sender" type="text" class="text-gray-600 dark:text-white input border
|
|
107
|
-
</div>
|
|
108
|
-
<div class="form-control">
|
|
109
|
-
<label class="label">
|
|
110
|
-
<span class="label-text">Balances</span>
|
|
111
|
-
</label>
|
|
112
|
-
<select v-model="denom" class="select select-bordered dark:
|
|
113
|
-
<option value="">Select a token</option>
|
|
114
|
-
<option v-for="{base, display} in showBalances" :value="base.denom">
|
|
115
|
-
{{ display.amount }} {{ display.denom }}
|
|
116
|
-
</option>
|
|
117
|
-
</select>
|
|
118
|
-
</div>
|
|
119
|
-
<div class="form-control">
|
|
120
|
-
<label class="label">
|
|
121
|
-
<span class="label-text">Recipient</span>
|
|
122
|
-
</label>
|
|
123
|
-
<input
|
|
124
|
-
v-model="recipient"
|
|
125
|
-
type="text"
|
|
126
|
-
class="input border
|
|
127
|
-
/>
|
|
128
|
-
</div>
|
|
129
|
-
<div class="form-control">
|
|
130
|
-
<label class="label">
|
|
131
|
-
<span class="label-text">Amount</span>
|
|
132
|
-
<span>{{ available.display.amount }} {{ formatDenom(available.display.denom) }}</span>
|
|
133
|
-
</label>
|
|
134
|
-
<label class="input-group">
|
|
135
|
-
<input v-model="amount" type="number" :placeholder="`Available: ${available?.display.amount}`" class="input border
|
|
136
|
-
<select v-model="amountDenom" class="select select-bordered dark:
|
|
137
|
-
<option v-for="u in units" :value="u.denom">{{ formatDenom(u.denom) }}</option>
|
|
138
|
-
</select>
|
|
139
|
-
</label>
|
|
140
|
-
</div>
|
|
141
|
-
</div>
|
|
142
|
-
</template>
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { PropType, computed, onMounted, ref } from 'vue';
|
|
3
|
+
import {
|
|
4
|
+
getStakingParam,
|
|
5
|
+
} from '../../../utils/http';
|
|
6
|
+
import { Coin, CoinMetadata } from '../../../utils/type';
|
|
7
|
+
import { TokenUnitConverter } from '../../../utils/TokenUnitConverter';
|
|
8
|
+
const props = defineProps({
|
|
9
|
+
endpoint: { type: String, required: true },
|
|
10
|
+
sender: { type: String, required: true },
|
|
11
|
+
balances: Object as PropType<Coin[]>,
|
|
12
|
+
metadata: Object as PropType<Record<string, CoinMetadata>>,
|
|
13
|
+
params: String,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const amount = ref('');
|
|
17
|
+
const recipient = ref('');
|
|
18
|
+
const denom = ref('');
|
|
19
|
+
const amountDenom = ref('')
|
|
20
|
+
|
|
21
|
+
const msgs = computed(() => {
|
|
22
|
+
const convert = new TokenUnitConverter(props.metadata)
|
|
23
|
+
return [
|
|
24
|
+
{
|
|
25
|
+
typeUrl: '/cosmos.bank.v1beta1.MsgSend',
|
|
26
|
+
value: {
|
|
27
|
+
fromAddress: props.sender,
|
|
28
|
+
toAddress: recipient.value,
|
|
29
|
+
amount: [
|
|
30
|
+
convert.displayToBase(denom.value, {
|
|
31
|
+
amount: String(amount.value),
|
|
32
|
+
denom: amountDenom.value
|
|
33
|
+
})
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
];
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const available = computed(() => {
|
|
41
|
+
const base = (
|
|
42
|
+
props.balances?.find((x) => x.denom === denom.value) || {
|
|
43
|
+
amount: '0',
|
|
44
|
+
denom: '-',
|
|
45
|
+
}
|
|
46
|
+
)
|
|
47
|
+
const convert = new TokenUnitConverter(props.metadata)
|
|
48
|
+
return {
|
|
49
|
+
base,
|
|
50
|
+
display: convert.baseToUnit(base, amountDenom.value)
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const showBalances = computed(() => {
|
|
55
|
+
const convert = new TokenUnitConverter(props.metadata)
|
|
56
|
+
return props.balances?.map(b => ({
|
|
57
|
+
base: b,
|
|
58
|
+
display: convert.baseToDisplay(b)
|
|
59
|
+
})) || []
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const units = computed(() => {
|
|
63
|
+
if(!props.metadata || !props.metadata[denom.value]) {
|
|
64
|
+
amountDenom.value = denom.value
|
|
65
|
+
return [{denom: denom.value, exponent: 0, aliases: []}]
|
|
66
|
+
}
|
|
67
|
+
const list = props.metadata[denom.value].denom_units.sort((a, b) => b.exponent - a.exponent)
|
|
68
|
+
if(list.length > 0) amountDenom.value = list[0].denom
|
|
69
|
+
return list
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
const isValid = computed(() => {
|
|
73
|
+
let ok = true
|
|
74
|
+
let error = ""
|
|
75
|
+
if(!recipient.value) {
|
|
76
|
+
ok = false
|
|
77
|
+
error = "Recipient is empty"
|
|
78
|
+
}
|
|
79
|
+
if(!(Number(amount.value) > 0)) {
|
|
80
|
+
ok = false
|
|
81
|
+
error = "Amount should be great than 0"
|
|
82
|
+
}
|
|
83
|
+
return { ok, error }
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
function initial() {
|
|
88
|
+
denom.value = props.params?.fees?.denom || '';
|
|
89
|
+
// getStakingParam(props.endpoint).then((x) => {
|
|
90
|
+
// denom.value = x.params?.bond_denom;
|
|
91
|
+
// });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function formatDenom(v: any) {
|
|
95
|
+
return String(v).substring(0, 10)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
defineExpose({msgs, isValid, initial})
|
|
99
|
+
</script>
|
|
100
|
+
<template>
|
|
101
|
+
<div class="dark:text-gray-400">
|
|
102
|
+
<div class="form-control">
|
|
103
|
+
<label class="label">
|
|
104
|
+
<span class="label-text">Sender</span>
|
|
105
|
+
</label>
|
|
106
|
+
<input :value="sender" type="text" class="text-gray-600 dark:text-white input border" />
|
|
107
|
+
</div>
|
|
108
|
+
<div class="form-control">
|
|
109
|
+
<label class="label">
|
|
110
|
+
<span class="label-text">Balances</span>
|
|
111
|
+
</label>
|
|
112
|
+
<select v-model="denom" class="select select-bordered dark:text-white">
|
|
113
|
+
<option value="">Select a token</option>
|
|
114
|
+
<option v-for="{base, display} in showBalances" :value="base.denom">
|
|
115
|
+
{{ display.amount }} {{ display.denom }}
|
|
116
|
+
</option>
|
|
117
|
+
</select>
|
|
118
|
+
</div>
|
|
119
|
+
<div class="form-control">
|
|
120
|
+
<label class="label">
|
|
121
|
+
<span class="label-text">Recipient</span>
|
|
122
|
+
</label>
|
|
123
|
+
<input
|
|
124
|
+
v-model="recipient"
|
|
125
|
+
type="text"
|
|
126
|
+
class="input border dark:text-white"
|
|
127
|
+
/>
|
|
128
|
+
</div>
|
|
129
|
+
<div class="form-control">
|
|
130
|
+
<label class="label">
|
|
131
|
+
<span class="label-text">Amount</span>
|
|
132
|
+
<span>{{ available.display.amount }} {{ formatDenom(available.display.denom) }}</span>
|
|
133
|
+
</label>
|
|
134
|
+
<label class="input-group">
|
|
135
|
+
<input v-model="amount" type="number" :placeholder="`Available: ${available?.display.amount}`" class="input border w-full dark:text-white" />
|
|
136
|
+
<select v-model="amountDenom" class="select select-bordered dark:text-white">
|
|
137
|
+
<option v-for="u in units" :value="u.denom">{{ formatDenom(u.denom) }}</option>
|
|
138
|
+
</select>
|
|
139
|
+
</label>
|
|
140
|
+
</div>
|
|
141
|
+
</div>
|
|
142
|
+
</template>
|