@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,174 +1,174 @@
|
|
|
1
|
-
<script lang="ts" setup>
|
|
2
|
-
import { ComputedRef, PropType, computed, onMounted, ref } from 'vue';
|
|
3
|
-
import {
|
|
4
|
-
getActiveValidators,
|
|
5
|
-
getInactiveValidators,
|
|
6
|
-
getStakingParam,
|
|
7
|
-
} from '../../../utils/http';
|
|
8
|
-
import { decimal2percent } from '../../../utils/format';
|
|
9
|
-
import { Coin, CoinMetadata } from '../../../utils/type';
|
|
10
|
-
import { TokenUnitConverter } from '../../../utils/TokenUnitConverter';
|
|
11
|
-
|
|
12
|
-
const props = defineProps({
|
|
13
|
-
endpoint: { type: String, required: true },
|
|
14
|
-
sender: { type: String, required: true },
|
|
15
|
-
balances: Object as PropType<Coin[]>,
|
|
16
|
-
metadata: Object as PropType<Record<string, CoinMetadata>>,
|
|
17
|
-
params: String,
|
|
18
|
-
});
|
|
19
|
-
const params = computed(() => JSON.parse(props.params || '{}'));
|
|
20
|
-
|
|
21
|
-
const validator = ref('');
|
|
22
|
-
|
|
23
|
-
const activeValidators = ref([]);
|
|
24
|
-
const inactiveValidators = ref([]);
|
|
25
|
-
const stakingDenom = ref('');
|
|
26
|
-
const unbondingTime = ref('');
|
|
27
|
-
const amount = ref('');
|
|
28
|
-
const amountDenom = ref('');
|
|
29
|
-
|
|
30
|
-
const msgs = computed(() => {
|
|
31
|
-
const convert = new TokenUnitConverter(props.metadata);
|
|
32
|
-
return [
|
|
33
|
-
{
|
|
34
|
-
typeUrl: '/cosmos.staking.v1beta1.MsgDelegate',
|
|
35
|
-
value: {
|
|
36
|
-
delegatorAddress: props.sender,
|
|
37
|
-
validatorAddress: validator.value,
|
|
38
|
-
amount: convert.displayToBase(stakingDenom.value, {
|
|
39
|
-
amount: String(amount.value),
|
|
40
|
-
denom: amountDenom.value,
|
|
41
|
-
}),
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
];
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
const list: ComputedRef<
|
|
48
|
-
{
|
|
49
|
-
operator_address: string;
|
|
50
|
-
description: { moniker: string };
|
|
51
|
-
commission: { commission_rates: { rate: string } };
|
|
52
|
-
status: string;
|
|
53
|
-
}[]
|
|
54
|
-
> = computed(() => {
|
|
55
|
-
return [...activeValidators.value, ...inactiveValidators.value];
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
const available = computed(() => {
|
|
59
|
-
const convert = new TokenUnitConverter(props.metadata);
|
|
60
|
-
const base = props.balances?.find(
|
|
61
|
-
(x) => x.denom === stakingDenom.value
|
|
62
|
-
) || { amount: '0', denom: stakingDenom.value };
|
|
63
|
-
return {
|
|
64
|
-
base,
|
|
65
|
-
display: convert.baseToUnit(base, amountDenom.value),
|
|
66
|
-
};
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
function loadInactiveValidators() {
|
|
70
|
-
getInactiveValidators(props.endpoint).then((x) => {
|
|
71
|
-
inactiveValidators.value = x.validators;
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const units = computed(() => {
|
|
76
|
-
if (!props.metadata || !props.metadata[stakingDenom.value]) {
|
|
77
|
-
amountDenom.value = stakingDenom.value;
|
|
78
|
-
return [{ denom: stakingDenom.value, exponent: 0, aliases: [] }];
|
|
79
|
-
}
|
|
80
|
-
const list = props.metadata[stakingDenom.value].denom_units.sort(
|
|
81
|
-
(a, b) => b.exponent - a.exponent
|
|
82
|
-
);
|
|
83
|
-
if (list.length > 0) amountDenom.value = list[0].denom;
|
|
84
|
-
return list;
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
const isValid = computed(() => {
|
|
88
|
-
let ok = true;
|
|
89
|
-
let error = '';
|
|
90
|
-
if (!validator.value) {
|
|
91
|
-
ok = false;
|
|
92
|
-
error = 'Validator is empty';
|
|
93
|
-
}
|
|
94
|
-
if (!(Number(amount.value) > 0)) {
|
|
95
|
-
ok = false;
|
|
96
|
-
error = 'Amount should be great than 0';
|
|
97
|
-
}
|
|
98
|
-
if (!amountDenom.value) {
|
|
99
|
-
ok = false;
|
|
100
|
-
error = 'Amount Denom is empty';
|
|
101
|
-
}
|
|
102
|
-
return { ok, error };
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
function initial() {
|
|
106
|
-
activeValidators.value = [];
|
|
107
|
-
validator.value = params.value.validator_address;
|
|
108
|
-
getStakingParam(props.endpoint).then((x) => {
|
|
109
|
-
stakingDenom.value = x.params.bond_denom;
|
|
110
|
-
unbondingTime.value = x.params.unbonding_time;
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
getActiveValidators(props.endpoint).then((x) => {
|
|
114
|
-
activeValidators.value = x.validators;
|
|
115
|
-
if (!params.value.validator_address) {
|
|
116
|
-
validator.value = x.validators.find(
|
|
117
|
-
(v) => v.description.identity === '6783E9F948541962'
|
|
118
|
-
)?.operator_address;
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
defineExpose({ msgs, isValid, initial });
|
|
124
|
-
</script>
|
|
125
|
-
<template>
|
|
126
|
-
<div>
|
|
127
|
-
<div class="form-control">
|
|
128
|
-
<label class="label">
|
|
129
|
-
<span class="label-text">Sender</span>
|
|
130
|
-
</label>
|
|
131
|
-
<input
|
|
132
|
-
:value="sender"
|
|
133
|
-
type="text"
|
|
134
|
-
class="text-gray-600 dark:text-white input border
|
|
135
|
-
/>
|
|
136
|
-
</div>
|
|
137
|
-
<div class="form-control">
|
|
138
|
-
<label class="label">
|
|
139
|
-
<span class="label-text">Validator</span>
|
|
140
|
-
<a class="label-text" @click="loadInactiveValidators()"
|
|
141
|
-
>Show Inactive</a
|
|
142
|
-
>
|
|
143
|
-
</label>
|
|
144
|
-
<select v-model="validator" class="select select-bordered dark:
|
|
145
|
-
<option value="">Select a validator</option>
|
|
146
|
-
<option v-for="v in list" :value="v.operator_address">
|
|
147
|
-
{{ v.description.moniker }} ({{
|
|
148
|
-
decimal2percent(v.commission.commission_rates.rate)
|
|
149
|
-
}}%)
|
|
150
|
-
<span v-if="v.status !== 'BOND_STATUS_BONDED'">x</span>
|
|
151
|
-
</option>
|
|
152
|
-
</select>
|
|
153
|
-
</div>
|
|
154
|
-
<div class="form-control">
|
|
155
|
-
<label class="label">
|
|
156
|
-
<span class="label-text">Amount</span>
|
|
157
|
-
<span>
|
|
158
|
-
{{ available?.display.amount }} {{ available?.display.denom }}
|
|
159
|
-
</span>
|
|
160
|
-
</label>
|
|
161
|
-
<label class="join">
|
|
162
|
-
<input
|
|
163
|
-
v-model="amount"
|
|
164
|
-
type="number"
|
|
165
|
-
:placeholder="`Available: ${available?.display.amount}`"
|
|
166
|
-
class="input border
|
|
167
|
-
/>
|
|
168
|
-
<select v-model="amountDenom" class="select select-bordered join-item dark:
|
|
169
|
-
<option v-for="u in units">{{ u.denom }}</option>
|
|
170
|
-
</select>
|
|
171
|
-
</label>
|
|
172
|
-
</div>
|
|
173
|
-
</div>
|
|
174
|
-
</template>
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { ComputedRef, PropType, computed, onMounted, ref } from 'vue';
|
|
3
|
+
import {
|
|
4
|
+
getActiveValidators,
|
|
5
|
+
getInactiveValidators,
|
|
6
|
+
getStakingParam,
|
|
7
|
+
} from '../../../utils/http';
|
|
8
|
+
import { decimal2percent } from '../../../utils/format';
|
|
9
|
+
import { Coin, CoinMetadata } from '../../../utils/type';
|
|
10
|
+
import { TokenUnitConverter } from '../../../utils/TokenUnitConverter';
|
|
11
|
+
|
|
12
|
+
const props = defineProps({
|
|
13
|
+
endpoint: { type: String, required: true },
|
|
14
|
+
sender: { type: String, required: true },
|
|
15
|
+
balances: Object as PropType<Coin[]>,
|
|
16
|
+
metadata: Object as PropType<Record<string, CoinMetadata>>,
|
|
17
|
+
params: String,
|
|
18
|
+
});
|
|
19
|
+
const params = computed(() => JSON.parse(props.params || '{}'));
|
|
20
|
+
|
|
21
|
+
const validator = ref('');
|
|
22
|
+
|
|
23
|
+
const activeValidators = ref([]);
|
|
24
|
+
const inactiveValidators = ref([]);
|
|
25
|
+
const stakingDenom = ref('');
|
|
26
|
+
const unbondingTime = ref('');
|
|
27
|
+
const amount = ref('');
|
|
28
|
+
const amountDenom = ref('');
|
|
29
|
+
|
|
30
|
+
const msgs = computed(() => {
|
|
31
|
+
const convert = new TokenUnitConverter(props.metadata);
|
|
32
|
+
return [
|
|
33
|
+
{
|
|
34
|
+
typeUrl: '/cosmos.staking.v1beta1.MsgDelegate',
|
|
35
|
+
value: {
|
|
36
|
+
delegatorAddress: props.sender,
|
|
37
|
+
validatorAddress: validator.value,
|
|
38
|
+
amount: convert.displayToBase(stakingDenom.value, {
|
|
39
|
+
amount: String(amount.value),
|
|
40
|
+
denom: amountDenom.value,
|
|
41
|
+
}),
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const list: ComputedRef<
|
|
48
|
+
{
|
|
49
|
+
operator_address: string;
|
|
50
|
+
description: { moniker: string };
|
|
51
|
+
commission: { commission_rates: { rate: string } };
|
|
52
|
+
status: string;
|
|
53
|
+
}[]
|
|
54
|
+
> = computed(() => {
|
|
55
|
+
return [...activeValidators.value, ...inactiveValidators.value];
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const available = computed(() => {
|
|
59
|
+
const convert = new TokenUnitConverter(props.metadata);
|
|
60
|
+
const base = props.balances?.find(
|
|
61
|
+
(x) => x.denom === stakingDenom.value
|
|
62
|
+
) || { amount: '0', denom: stakingDenom.value };
|
|
63
|
+
return {
|
|
64
|
+
base,
|
|
65
|
+
display: convert.baseToUnit(base, amountDenom.value),
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
function loadInactiveValidators() {
|
|
70
|
+
getInactiveValidators(props.endpoint).then((x) => {
|
|
71
|
+
inactiveValidators.value = x.validators;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const units = computed(() => {
|
|
76
|
+
if (!props.metadata || !props.metadata[stakingDenom.value]) {
|
|
77
|
+
amountDenom.value = stakingDenom.value;
|
|
78
|
+
return [{ denom: stakingDenom.value, exponent: 0, aliases: [] }];
|
|
79
|
+
}
|
|
80
|
+
const list = props.metadata[stakingDenom.value].denom_units.sort(
|
|
81
|
+
(a, b) => b.exponent - a.exponent
|
|
82
|
+
);
|
|
83
|
+
if (list.length > 0) amountDenom.value = list[0].denom;
|
|
84
|
+
return list;
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
const isValid = computed(() => {
|
|
88
|
+
let ok = true;
|
|
89
|
+
let error = '';
|
|
90
|
+
if (!validator.value) {
|
|
91
|
+
ok = false;
|
|
92
|
+
error = 'Validator is empty';
|
|
93
|
+
}
|
|
94
|
+
if (!(Number(amount.value) > 0)) {
|
|
95
|
+
ok = false;
|
|
96
|
+
error = 'Amount should be great than 0';
|
|
97
|
+
}
|
|
98
|
+
if (!amountDenom.value) {
|
|
99
|
+
ok = false;
|
|
100
|
+
error = 'Amount Denom is empty';
|
|
101
|
+
}
|
|
102
|
+
return { ok, error };
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
function initial() {
|
|
106
|
+
activeValidators.value = [];
|
|
107
|
+
validator.value = params.value.validator_address;
|
|
108
|
+
getStakingParam(props.endpoint).then((x) => {
|
|
109
|
+
stakingDenom.value = x.params.bond_denom;
|
|
110
|
+
unbondingTime.value = x.params.unbonding_time;
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
getActiveValidators(props.endpoint).then((x) => {
|
|
114
|
+
activeValidators.value = x.validators;
|
|
115
|
+
if (!params.value.validator_address) {
|
|
116
|
+
validator.value = x.validators.find(
|
|
117
|
+
(v) => v.description.identity === '6783E9F948541962'
|
|
118
|
+
)?.operator_address;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
defineExpose({ msgs, isValid, initial });
|
|
124
|
+
</script>
|
|
125
|
+
<template>
|
|
126
|
+
<div>
|
|
127
|
+
<div class="form-control">
|
|
128
|
+
<label class="label">
|
|
129
|
+
<span class="label-text">Sender</span>
|
|
130
|
+
</label>
|
|
131
|
+
<input
|
|
132
|
+
:value="sender"
|
|
133
|
+
type="text"
|
|
134
|
+
class="text-gray-600 dark:text-white input border"
|
|
135
|
+
/>
|
|
136
|
+
</div>
|
|
137
|
+
<div class="form-control">
|
|
138
|
+
<label class="label">
|
|
139
|
+
<span class="label-text">Validator</span>
|
|
140
|
+
<a class="label-text" @click="loadInactiveValidators()"
|
|
141
|
+
>Show Inactive</a
|
|
142
|
+
>
|
|
143
|
+
</label>
|
|
144
|
+
<select v-model="validator" class="select select-bordered dark:text-white">
|
|
145
|
+
<option value="">Select a validator</option>
|
|
146
|
+
<option v-for="v in list" :value="v.operator_address">
|
|
147
|
+
{{ v.description.moniker }} ({{
|
|
148
|
+
decimal2percent(v.commission.commission_rates.rate)
|
|
149
|
+
}}%)
|
|
150
|
+
<span v-if="v.status !== 'BOND_STATUS_BONDED'">x</span>
|
|
151
|
+
</option>
|
|
152
|
+
</select>
|
|
153
|
+
</div>
|
|
154
|
+
<div class="form-control">
|
|
155
|
+
<label class="label">
|
|
156
|
+
<span class="label-text">Amount</span>
|
|
157
|
+
<span>
|
|
158
|
+
{{ available?.display.amount }} {{ available?.display.denom }}
|
|
159
|
+
</span>
|
|
160
|
+
</label>
|
|
161
|
+
<label class="join">
|
|
162
|
+
<input
|
|
163
|
+
v-model="amount"
|
|
164
|
+
type="number"
|
|
165
|
+
:placeholder="`Available: ${available?.display.amount}`"
|
|
166
|
+
class="input border w-full join-item dark:text-white"
|
|
167
|
+
/>
|
|
168
|
+
<select v-model="amountDenom" class="select select-bordered join-item dark:text-white">
|
|
169
|
+
<option v-for="u in units">{{ u.denom }}</option>
|
|
170
|
+
</select>
|
|
171
|
+
</label>
|
|
172
|
+
</div>
|
|
173
|
+
</div>
|
|
174
|
+
</template>
|
|
@@ -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
|
|
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
|
|
91
|
-
<select v-model="amountDenom" class="select select-bordered dark:
|
|
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" />
|
|
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 w-full dark:text-white" />
|
|
91
|
+
<select v-model="amountDenom" class="select select-bordered dark:text-white">
|
|
92
|
+
<option v-for="u in units">{{ u.denom }}</option>
|
|
93
|
+
</select>
|
|
94
|
+
</label>
|
|
95
|
+
</div>
|
|
96
|
+
</div>
|
|
97
97
|
</template>
|