12 text-overflow: ellipsis;
17 .topbar-left .btn-menu {
21 .topbar-left .btn-menu i {
30 .topbar .topbar-right {
34 border: 2px solid #fff;
42 display: inline-block;
46 background-color: #02f823;
57 .content .token-icon {
67 .content .token-amount {
71 .token-amount .asset {
77 vertical-align: middle;
101 border-bottom: 1px solid #5e5e5e;
119 <div id="app" class="warp">
120 <section class="bg-green">
122 <div class="topbar-right">
124 <select v-model="network" @change="networkToggle">
125 <option value="mainnet">{{ $t('main.mainNet') }}</option>
126 <option value="testnet">{{ $t('main.testNet') }}</option>
129 <div class="topbar-left">
130 <a class="btn-menu" href="#">
131 <i class="iconfont icon-menu" @click="$refs.menu.open()"></i>
133 <span class="alias">{{currentAccount.alias}}</span>
136 <div class="content">
137 <img src="../../assets/logo.png" class="token-icon">
138 <div v-if="currentAccount.address!=undefined" class="amount">
139 <div class="token-amount">
140 {{currentAccount.balance}}
141 <span class="asset">BTM</span>
143 <p class="account-address">
144 <span class="address-text" :title="addressTitle" :data-clipboard-text="currentAccount.address">{{currentAccount.address_short}}</span>
145 <i class="iconfont qrcode" @click="showQrcode"></i>
148 <a v-if="currentAccount.address!=undefined" class="btn btn-primary btn-transfer" @click="transferOpen">{{ $t('main.transfer') }}</a>
152 <section v-if="currentAccount.address!=undefined" class="transactions">
153 <h3 class="bg-gray">{{ $t('main.record') }}</h3>
154 <vue-scroll @handle-scroll="handleScroll">
156 <li class="list-item" v-for="(transcation, index) in transcations" :key="index" @click="$refs.trxInfo.open(transcation, currentAccount.address)">
157 <div class="value">{{transcation.direct}} {{transcation.val.toFixed(2)}} BTM</div>
159 <div v-if="transcation.is_confirmed" class="time">{{transcation.block_timestamp | moment}}</div>
160 <div v-else class="time">{{transcation.submission_timestamp | moment}}</div>
161 <div class="addr">{{transcation.address}}</div>
168 <p style="width: 250px; margin: 30px auto; text-align: center;">{{ $t('main.noAccount') }}</p>
169 <a class="btn btn-primary btn-creation bg-green" @click="$refs.menu.open('creation')">{{ $t('main.create') }}</a>
173 <Qrcode ref="qrcode"></Qrcode>
174 <Menu ref="menu" :accounts="accounts" :selectedAccount="currentAccount" @on-account-change="accountToggle"></Menu>
175 <Transfer ref="transfer" :fee="fee" :feeTypeOptions="feeTypeOptions" @on-success="refreshAccounts"></Transfer>
176 <TxInfo ref="trxInfo" @on-success="refreshTransactions"></TxInfo>
181 import ClipboardJS from "clipboard";
182 import Menu from "../home/menu";
183 import Qrcode from "../transfer/qrcode";
184 import Transfer from "../transfer/transfer";
185 import TxInfo from "../transfer/detail";
186 import account from "../../models/account";
187 import transaction from "../../models/transaction";
188 import utils from "../common/utils";
199 feeTypeOptions: [this.$t("transfer.feeType")],
200 fee: this.$t("transfer.feeType"),
202 clipboard: new ClipboardJS(".address-text"),
203 addressTitle: this.$t("main.copy"),
214 currentAccount(newVal) {
215 if (newVal.guid == undefined) {
219 this.setupShortAddr(newVal.address)
220 this.refreshBalance(newVal.guid);
221 this.refreshTransactions(newVal.guid, newVal.address).then(transcations => {
222 this.transcations = transcations
227 setupShortAddr(address) {
228 this.currentAccount.address_short = utils.shortAddress(address);
231 this.clipboard.on("success", e => {
233 header: this.$t("dialog.header"),
234 body: this.$t("dialog.copy.success")
237 this.clipboard.on("error", e => {
239 header: this.$t("dialog.header"),
240 body: this.$t("dialog.copy.fail")
244 setupRefreshTimer() {
246 this.refreshBalance(this.currentAccount.guid)
250 this.network = localStorage.bytomNet;
251 account.setupNet(this.network);
253 networkToggle: function (val) {
254 localStorage.bytomNet = this.network;
255 account.setupNet(this.network);
256 this.refreshAccounts();
258 accountToggle: function (selectedAccount) {
259 localStorage.currentAccount = JSON.stringify(selectedAccount);
260 this.currentAccount = selectedAccount;
261 this.refreshAccounts();
263 showQrcode: function () {
264 this.$refs.qrcode.open(this.currentAccount.address);
266 transferOpen: function () {
267 this.fee = this.$t("transfer.feeType");
268 this.feeTypeOptions = [this.$t("transfer.feeType")];
269 this.$refs.transfer.open(this.currentAccount);
271 transcationsFormat: function (transactions) {
272 transactions.forEach(transaction => {
275 let selfInputSum = 0;
276 let selfoutputSum = 0;
277 let inputAddresses = [];
278 let outputAddresses = [];
279 transaction.inputs.forEach(input => {
280 inputSum += input.amount;
281 if (input.address == this.currentAccount.address) {
282 selfInputSum += input.amount;
286 inputAddresses.push(input.address);
288 transaction.outputs.forEach(output => {
289 outputSum += output.amount;
290 if (output.address == this.currentAccount.address) {
291 selfoutputSum += output.amount;
295 outputAddresses.push(output.address);
298 let val = selfoutputSum - selfInputSum;
300 transaction.direct = "+";
301 transaction.address = utils.shortAddress(inputAddresses.pop());
303 val = selfInputSum - selfoutputSum;
304 transaction.direct = "-";
305 transaction.address = utils.shortAddress(outputAddresses.pop());
307 transaction.val = Number(val / 100000000);
308 transaction.fee = Number(inputSum - outputSum) / 100000000;
311 refreshAccounts: function () {
312 account.list().then(accounts => {
313 this.accounts = accounts;
314 if (accounts.length == 0) {
318 if (localStorage.currentAccount != undefined) {
319 this.currentAccount = JSON.parse(localStorage.currentAccount);
321 this.currentAccount = accounts[0];
325 refreshBalance: function (guid) {
326 account.balance(guid).then(balance => {
327 this.currentAccount.balance = balance
332 refreshTransactions: function (guid, address) {
333 return new Promise((resolve, reject) => {
334 transaction.list(guid, address).then(ret => {
335 let transactions = ret.result.data;
336 if (transactions == null) {
340 this.transcationsFormat(transactions);
341 console.log("formatTx", transactions);
342 resolve(transactions)
349 handleScroll(vertical, horizontal, nativeEvent) {
350 if (vertical.process == 0) {
355 if (vertical.process == 1) {
356 this.start += this.limit;
357 this.refreshTransactions(this.currentAccount.guid, this.currentAccount.address).then(transcations => {
358 transactions.forEach(transaction => {
359 this.transcations.push(transaction);
366 this.setupClipboard();
367 this.setupRefreshTimer();
369 this.refreshAccounts();
372 this.clipboard.destroy();