This repository has been archived by the owner on Dec 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-wallet.vue
258 lines (246 loc) · 7.85 KB
/
add-wallet.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<template>
<div>
<p v-if="$fetchState.pending"></p>
<p v-else-if="$fetchState.error">An error occurred</p>
<div v-else>
<v-row justify="center" align="center" class="pa-md-8 mx-lg-auto">
<v-col cols="12" sm="8" md="6">
<v-alert
v-if="viewError"
border="right"
colored-border
type="error"
elevation="2"
>
{{ viewErrorMsg }}
</v-alert>
<v-card min-height="380px">
<v-card-title>
Add wallet
</v-card-title>
<v-card-text>
<v-form v-model="valid">
<v-row>
<v-col
cols="12"
md="12"
>
<v-text-field
outlined
v-model="walletName"
:rules="nameRules"
:counter="20"
label="Wallet name"
required
></v-text-field>
</v-col>
<v-col
cols="12"
md="12"
>
<v-text-field
outlined
v-model="mnemonic"
:rules="mnemonicRules"
label="Your mnemonic"
type="password"
autoComplete="true"
></v-text-field>
Address: <b>{{ addressWallet }}</b>
</v-col>
<v-col
cols="12"
md="12"
>
<v-text-field
outlined
v-model="password"
:rules="passRules"
label="Password"
type="password"
autoComplete="true"
></v-text-field>
</v-col>
</v-row>
</v-form>
</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn
color="primary"
:disabled="!valid"
nuxt
@click="addWallet"
>
Add wallet
</v-btn>
</v-card-actions>
</v-card>
<br />
<v-card>
<v-card-title>
Your wallets
</v-card-title>
<v-card-text>
<v-expansion-panels>
<v-expansion-panel
v-for="item in allWallets"
:key="item.name"
>
<v-expansion-panel-header>
{{ item.name }}
</v-expansion-panel-header>
<v-expansion-panel-content>
<v-simple-table>
<template v-slot:default>
<thead>
<tr>
<th class="text-left">
Chain
</th>
<th class="text-left">
Address
</th>
</tr>
</thead>
<!-- <tbody>
<tr>
<td>{{ item.name }} </td>
<td>directsecp256k1hdwallet-v1</td>
<td>
<v-btn
color="error"
@click="deleteWallet(item.name)"
>
Delete
</v-btn>
</td>
</tr>
</tbody>-->
<tbody>
<tr
v-for="conf in item.allAddress"
:key="conf.chain"
>
<td>
<v-avatar size="36">
<img
:src="conf.img"
:alt="conf.img"
>
</v-avatar>
<b>{{ conf.chain }}</b> </td>
<td><a :href="conf.mintscanId" target="_blank"> {{ conf.addr }}</a> </td>
</tr>
</tbody>
</template>
</v-simple-table>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn
color="error"
@click="deleteWallet(item.name)"
>
Delete
</v-btn>
</v-card-actions>
</v-expansion-panel-content>
</v-expansion-panel>
</v-expansion-panels>
</v-card-text>
</v-card>
</v-col>
</v-row>
</div>
</div>
</template>
<script>
import { mapState } from 'vuex'
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing"
import cosmosConfig from '~/cosmos.config'
export default {
data: () => ({
valid: false,
walletName: '',
mnemonic: '',
password: '',
viewError: false,
viewErrorMsg: '',
listWallets: '',
dialogDetail: false,
addressWallet: '',
addressWalletError: false,
cosmosConfig: cosmosConfig,
nameRules: [
v => !!v || 'Name is required',
v => v.length <= 20 || 'Name must be less than 20 characters',
],
mnemonicRules: [
v => !!v || 'Mnemonic is required',
],
passRules: [
v => !!v || 'Password is required'
],
}),
computed: {
...mapState('data', ['allProcess', 'allProcessLoaded', 'allWallets', 'logged', 'userToken']),
},
watch:{
async 'mnemonic'(newVal){
try {
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(newVal, {
prefix: 'cosmos'
});
const [firstAccount] = await wallet.getAccounts()
console.log(firstAccount)
this.addressWallet = firstAccount.address
} catch (error) {
console.log(error)
this.addressWallet = error
}
}
},
async fetch() {
let checkToken = await this.$store.dispatch('data/checkToken')
if (!checkToken) {
this.$router.push('/login')
}
},
async mounted () {
let checkToken = await this.$store.dispatch('data/checkToken')
if (checkToken) {
await this.$store.dispatch('data/getAllWallets')
}
},
methods: {
async addWallet() {
try {
const wallet = await DirectSecp256k1HdWallet.fromMnemonic( this.mnemonic )
var finalWallet = await wallet.serialize( this.password )
const response = await this.$axios.post('/api/wallets/add', {
name: this.walletName,
data: finalWallet,
token: this.userToken,
address: this.addressWallet
})
await this.$store.dispatch('data/getAllWallets')
} catch (error) {
this.viewError = true
this.viewErrorMsg = error
}
},
async deleteWallet(walletName) {
try {
const response = await this.$axios.post('/api/wallets/delete', {
name: walletName,
token: this.userToken
})
await this.$store.dispatch('data/getAllWallets')
} catch (error) {
this.viewError = true
this.viewErrorMsg = error
}
},
},
}
</script>