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;
84 .transaction-title h3 {
101 border-bottom: 1px solid #5e5e5e;
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" @click="openMenu">
131 <i class="iconfont icon-menu"></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">
141 <span class="asset">BTM</span>
143 <p class="account-address">
144 <span class="address-text" :title="addressTitle" :data-clipboard-text="currentAccount.address">{{shortAddress}}</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 <div v-if="currentAccount.address!=undefined">
153 <section class="transaction-title">
154 <h3 class="bg-gray">{{ $t('main.record') }}</h3>
156 <section class="transactions">
157 <vue-scroll @handle-scroll="handleScroll">
159 <li class="list-item" v-for="(transcation, index) in transactions" :key="index" @click="$router.push({name: 'transfer-info', params: {transcation: transcation, address: currentAccount.address}})">
160 <div class="value">{{transcation.direct}} {{transcation.val.toFixed(2)}} BTM</div>
162 <div v-if="transcation.is_confirmed" class="time">{{transcation.block_timestamp | moment}}</div>
163 <div v-else class="time">{{transcation.submission_timestamp | moment}}</div>
164 <div class="addr">{{transcation.address}}</div>
172 <p style="width: 250px; margin: 30px auto; text-align: center;">{{ $t('main.noAccount') }}</p>
173 <a class="btn btn-primary btn-creation bg-green" @click="$refs.menu.open('creation')">{{ $t('main.create') }}</a>
177 <div class="mask" v-show="maskShow"></div>
178 <transition :enter-active-class="enterActive" :leave-active-class="leaveActive">
179 <router-view></router-view>
183 <Qrcode ref="qrcode"></Qrcode>
188 import ClipboardJS from "clipboard";
189 import Menu from "@/views/homeMenu";
190 import Qrcode from "@/views/qrcode";
191 import Transfer from "@/views/transfer";
192 import TxInfo from "@/views/transferDetail";
193 import address from "@/utils/address";
194 import account from "@/models/account";
195 import transaction from "@/models/transaction";
196 const EnterActive = 'animated faster fadeInLeft';
197 const LeaveActive = 'animated faster fadeOutLeft';
206 clipboard: new ClipboardJS(".address-text"),
207 addressTitle: this.$t("main.copy"),
216 enterActive: EnterActive,
217 leaveActive: LeaveActive,
222 if (to.name.startsWith('menu')) {
224 } else if (from.name.startsWith('menu')) {
225 this.maskShow = false
228 //account toggle by the list from menu
229 if (to.name == 'home' && to.params.selectedAccount != undefined && from.name == 'menu') {
230 this.currentAccount = to.params.selectedAccount
233 // remove transition for some page
234 this.enterActive = EnterActive
235 this.leaveActive = LeaveActive
236 if (to.name == 'transfer-confirm' || from.name == 'transfer-confirm') {
237 this.enterActive = ''
238 this.leaveActive = ''
241 currentAccount(newVal, oldVal) {
242 localStorage.currentAccount = JSON.stringify(newVal);
243 if (newVal.guid == undefined) {
247 this.refreshTransactions(newVal.guid, newVal.address).then(transactions => {
248 this.transactions = transactions
253 shortAddress: function () {
254 return address.short(this.currentAccount.address)
256 accountBalance: function () {
257 return this.currentAccount.balance
261 setupShortAddr(rawAddress) {
262 this.currentAccount.address_short = address.short(rawAddress);
265 this.clipboard.on("success", e => {
267 header: this.$t("dialog.header"),
268 body: this.$t("dialog.copy.success")
271 this.clipboard.on("error", e => {
273 header: this.$t("dialog.header"),
274 body: this.$t("dialog.copy.fail")
278 setupRefreshTimer() {
279 // todo refresh all accounts
282 this.refreshBalance(this.currentAccount.guid)
286 this.network = localStorage.bytomNet;
287 account.setupNet(this.network);
289 networkToggle: function (val) {
290 localStorage.bytomNet = this.network;
291 account.setupNet(this.network);
292 this.refreshAccounts();
294 showQrcode: function () {
295 this.$refs.qrcode.open(this.currentAccount.address);
297 openMenu: function () {
298 this.$router.push({ name: 'menu', params: { accounts: this.accounts, selected: this.currentAccount } })
300 transferOpen: function () {
301 this.$router.push({ name: 'transfer', params: { account: this.currentAccount } })
303 handleScroll(vertical, horizontal, nativeEvent) {
304 if (vertical.process == 0) {
306 this.refreshTransactions(this.currentAccount.guid, this.currentAccount.address).then(transactions => {
307 this.transactions = transactions
312 if (vertical.process == 1) {
313 this.start += this.limit;
314 this.refreshTransactions(this.currentAccount.guid, this.currentAccount.address, this.start, this.limit).then(transactions => {
315 transactions.forEach(transaction => {
316 this.transactions.push(transaction);
321 refreshAccounts: function () {
322 account.list().then(accounts => {
323 this.accounts = accounts;
324 if (accounts.length == 0) {
328 if (localStorage.currentAccount != undefined) {
329 this.currentAccount = JSON.parse(localStorage.currentAccount);
331 this.currentAccount = accounts[0];
335 refreshBalance: function (guid) {
336 account.balance(guid).then(balance => {
337 this.currentAccount.balance = balance;
338 this.currentAccount = Object.assign({}, this.currentAccount);
343 refreshTransactions: function (guid, address, start, limit) {
344 return new Promise((resolve, reject) => {
345 transaction.list(guid, address, start, limit).then(ret => {
346 let transactions = ret.result.data;
347 if (transactions == null) {
351 this.transactionsFormat(transactions);
352 console.log("formatTx", transactions);
353 resolve(transactions)
360 transactionsFormat: function (transactions) {
361 transactions.forEach(transaction => {
364 let selfInputSum = 0;
365 let selfoutputSum = 0;
366 let inputAddresses = [];
367 let outputAddresses = [];
368 transaction.inputs.forEach(input => {
369 inputSum += input.amount;
370 if (input.address == this.currentAccount.address) {
371 selfInputSum += input.amount;
375 inputAddresses.push(input.address);
377 transaction.outputs.forEach(output => {
378 outputSum += output.amount;
379 if (output.address == this.currentAccount.address) {
380 selfoutputSum += output.amount;
384 outputAddresses.push(output.address);
387 let val = selfoutputSum - selfInputSum;
389 transaction.direct = "+";
390 transaction.address = address.short(inputAddresses.pop());
392 val = selfInputSum - selfoutputSum;
393 transaction.direct = "-";
394 transaction.address = address.short(outputAddresses.pop());
396 transaction.val = Number(val / 100000000);
397 transaction.fee = Number(inputSum - outputSum) / 100000000;
403 this.setupClipboard();
404 this.setupRefreshTimer();
405 this.refreshAccounts();
408 this.clipboard.destroy();