-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexternal-test.vue
More file actions
62 lines (55 loc) · 1.21 KB
/
external-test.vue
File metadata and controls
62 lines (55 loc) · 1.21 KB
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
<template>
<div>
Hello {{$store.state.ual.accountName}}
<q-btn label="test" color="primary" @click="getUserBalance()" :loading="is_loading"></q-btn>
<pre v-if="res" >{{res}}</pre>
</div>
</template>
<script>
module.exports = {
name: 'externalComponent',
props:{
token:{
type: Object,
default: ()=>{return {contract:"eosio.token",symbol:"EOS"}}
}
},
data () {
return {
res: false,
is_loading: false,
account: this.$store.state.ual.accountName
}
},
methods:{
async getUserBalance() {
this.is_loading = true;
let symbol = this.token.symbol;
let query = {
json: true,
code: this.token.contract,
scope: this.account,
table: "accounts",
limit: 1,
};
let r = (await this.$eos.rpc.get_table_rows(query)).rows[0];
if (!r) {
r = {
balance: `0 ${symbol}`,
amount: 0,
symbol: symbol,
precision: 4,
contract: this.token.contract,
};
} else {
r.amount = parseFloat(r.balance.split(" ")[0]);
r.symbol = symbol;
r.precision = 4;
r.contract = this.token.contract;
}
this.res = r;
this.is_loading = false;
}
}
}
</script>