11<template >
22 <div id =" app" >
3- <div
4- v-if =" isSupportedBrowser"
5- class =" supportedbrowser--alert"
6- >
7- {{ $t('noExtensionSupport') }}
8- </div >
93 <MobileNavigation v-if =" !$route.meta.fullScreen" />
104 <div class =" not-bootstrap-row" >
115 <div
3327
3428<script >
3529import { mapMutations , mapState , mapGetters } from ' vuex' ;
36- import { detect } from ' detect-browser' ;
37- import {
38- client , initClient , scanForWallets , tokenBalance ,
39- } from ' ./utils/aeternity' ;
30+ import { initSdk , scanForWallets , tokenBalance } from ' ./utils/aeternity' ;
4031import Backend from ' ./utils/backend' ;
4132import { EventBus } from ' ./utils/eventBus' ;
42- import { IS_MOBILE_DEVICE , supportedBrowsers , atomsToAe } from ' ./utils' ;
33+ import { atomsToAe } from ' ./utils' ;
4334import MobileNavigation from ' ./components/layout/MobileNavigation.vue' ;
4435import LeftSection from ' ./components/layout/LeftSection.vue' ;
4536import RightSection from ' ./components/layout/RightSection.vue' ;
@@ -48,31 +39,28 @@ export default {
4839 components: { MobileNavigation, LeftSection, RightSection },
4940 computed: {
5041 ... mapGetters (' modals' , [' opened' ]),
51- ... mapState ([' address' ]),
52- isSupportedBrowser () {
53- const browser = detect ();
54- return ! IS_MOBILE_DEVICE && (browser && ! supportedBrowsers .includes (browser .name ));
55- },
42+ ... mapState ([' address' , ' sdk' ]),
5643 },
5744 async created () {
5845 EventBus .$on (' reloadData' , () => {
5946 this .reloadData ();
6047 });
6148 setInterval (() => this .reloadData (), 120 * 1000 );
62- EventBus .$on (' backendError' , () => this .$route .name !== ' maintenance' && this .$router .push ({
63- name: ' maintenance' ,
64- }).catch ((err ) => { console .error (err); }));
65- await this .initialLoad ();
49+
50+ await initSdk ();
51+ await Promise .all ([
52+ this .initWallet (),
53+ this .reloadData (),
54+ ]);
6655 },
6756 methods: {
6857 ... mapMutations ([
69- ' setLoggedInAccount ' , ' updateTopics' , ' updateCurrencyRates' ,
70- ' setOracleState' , ' addLoading ' , ' removeLoading ' , ' setChainNames' , ' updateBalance' ,
58+ ' setAddress ' , ' updateTopics' , ' updateCurrencyRates' ,
59+ ' setOracleState' , ' setChainNames' , ' updateBalance' ,
7160 ' setGraylistedUrls' , ' setTokenInfo' , ' setVerifiedUrls' , ' useSdkWallet' , ' addTokenBalance' ,
7261 ' setPinnedItems' ,
7362 ]),
7463 async reloadData () {
75- // await fetch
7664 const [
7765 chainNames, oracleState, topics, verifiedUrls, graylistedUrls, tokenInfo,
7866 ] = await Promise .all ([
@@ -84,62 +72,42 @@ export default {
8472 Backend .getTokenInfo (),
8573 this .$store .dispatch (' backend/reloadStats' ),
8674 this .$store .dispatch (' backend/reloadPrices' ),
75+ this .reloadUserData (),
8776 ]);
8877
89- if (this .address ) {
90- const balance = await client .balance (this .address ).catch (() => 0 );
91- this .updateBalance (atomsToAe (balance).toFixed (2 ));
92- }
93-
94- // async fetch
9578 this .updateTopics (topics);
9679 this .setChainNames (chainNames);
9780 this .setOracleState (oracleState);
9881 this .setGraylistedUrls (graylistedUrls);
9982 this .setVerifiedUrls (verifiedUrls);
10083 this .setTokenInfo (tokenInfo);
101- if (this .address ) this .loadTokenBalances (this .address );
10284 },
103- async fetchUserData () {
85+ async reloadUserData () {
86+ if (! this .address ) return ;
10487 await Promise .all ([
10588 this .$store .dispatch (' updatePinnedItems' ),
10689 this .$store .dispatch (' updateUserProfile' ),
90+ (async () => {
91+ const balance = await this .sdk .balance (this .address ).catch (() => 0 );
92+ this .updateBalance (atomsToAe (balance).toFixed (2 ));
93+ })(),
94+ (async () => {
95+ const tokens = await Backend .getTokenBalances (this .address );
96+ await Promise .all (Object .entries (tokens).map (async ([token ]) => this
97+ .addTokenBalance ({ token, balance: await tokenBalance (token, this .address ) })));
98+ })(),
10799 ]);
108100 },
109- async initialLoad () {
110- this .addLoading (' initial' );
111- this .addLoading (' wallet' );
112- await initClient ();
113- await this .reloadData ();
114- this .removeLoading (' initial' );
115- if (this .address ) {
116- this .removeLoading (' wallet' );
117- this .fetchUserData ();
118- }
119-
101+ async initWallet () {
120102 let { address } = this .$route .query ;
121103 if (! address) {
122- await scanForWallets ();
123- address = client .rpcClient .getCurrentAccount ();
104+ address = await scanForWallets ();
124105 console .log (' found wallet' );
125106 this .useSdkWallet ();
107+ this .$store .dispatch (' updateCookiesConsent' , address);
126108 }
127- const balance = await client .balance (address).catch (() => 0 );
128- this .setLoggedInAccount ({
129- address,
130- balance: atomsToAe (balance).toFixed (2 ),
131- });
132-
133- // trigger run async in background
134- this .loadTokenBalances (address);
135-
136- this .fetchUserData ();
137- this .removeLoading (' wallet' );
138- },
139- async loadTokenBalances (address ) {
140- const tokens = await Backend .getTokenBalances (address);
141- await Promise .all (Object .entries (tokens).map (async ([token ]) => this
142- .addTokenBalance ({ token, balance: await tokenBalance (token, address) })));
109+ this .setAddress (address);
110+ await this .reloadUserData ();
143111 },
144112 },
145113};
@@ -178,11 +146,6 @@ export default {
178146 display : flex ;
179147 flex-direction : column ;
180148
181- .supportedbrowser--alert {
182- text-align : center ;
183- line-height : 3rem ;
184- }
185-
186149 .not-bootstrap-row {
187150 flex-grow : 1 ;
188151 display : flex ;
0 commit comments