From d76a0da14a0e49a2b40de955ac807f94fd8ab8fc Mon Sep 17 00:00:00 2001 From: Nikita Cedrik Date: Wed, 1 Sep 2021 11:48:19 +1000 Subject: [PATCH 01/65] refactor: remove unused mapped states --- src/popup/router/components/AccountInfo.vue | 2 +- src/popup/router/components/AccountSwitcher.vue | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/popup/router/components/AccountInfo.vue b/src/popup/router/components/AccountInfo.vue index 6aaf8f5c0..413fca2e4 100644 --- a/src/popup/router/components/AccountInfo.vue +++ b/src/popup/router/components/AccountInfo.vue @@ -146,7 +146,7 @@ export default { UNFINISHED_FEATURES: process.env.UNFINISHED_FEATURES, }), computed: { - ...mapState(['accountCount', 'accountSelectedIdx', 'cardMinified']), + ...mapState(['accountSelectedIdx', 'cardMinified']), ...mapGetters(['accounts', 'activeNetwork']), idx() { return this.accountIdx === -1 ? this.accountSelectedIdx : this.accountIdx; diff --git a/src/popup/router/components/AccountSwitcher.vue b/src/popup/router/components/AccountSwitcher.vue index 0ec3d6409..62d362fb8 100644 --- a/src/popup/router/components/AccountSwitcher.vue +++ b/src/popup/router/components/AccountSwitcher.vue @@ -38,7 +38,7 @@ export default { components: { AccountCard, ButtonPlain }, props: { notification: Boolean }, computed: { - ...mapState(['accountCount', 'accountSelectedIdx']), + ...mapState(['accountSelectedIdx']), ...mapGetters(['accounts']), cssVars() { return { From 4ddd3c1f1cf10b5cf959ee5f3ddeef51a807ca69 Mon Sep 17 00:00:00 2001 From: Nikita Cedrik Date: Tue, 31 Aug 2021 18:58:39 +1000 Subject: [PATCH 02/65] chore(accounts): move account plugin to module --- src/store/index.js | 4 ++-- src/store/{plugins/account.js => modules/accounts.js} | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) rename src/store/{plugins/account.js => modules/accounts.js} (96%) diff --git a/src/store/index.js b/src/store/index.js index 774b9ef28..daca24d80 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -8,12 +8,12 @@ import observables from './plugins/observables'; import persistState from './plugins/persistState'; import modals from './plugins/modals'; import tipUrl from './plugins/tipUrl'; -import accounts from './plugins/account'; import namesPlugin from './plugins/names'; import pendingTransactionHandler from './plugins/pendingTransactionHandler'; import languagesPlugin from './plugins/languages'; import openErrorModalPlugin from './plugins/openErrorModal'; import runMigrations from './migrations'; +import accountsModule from './modules/accounts'; import invitesModule from './modules/invites'; import permissionsModule from './modules/permissions'; import transactionCacheModule from './modules/transactionCache'; @@ -78,7 +78,6 @@ export default new Vuex.Store({ observables, modals, tipUrl, - accounts, namesPlugin, fungibleTokensPlugin, pendingTransactionHandler, @@ -88,6 +87,7 @@ export default new Vuex.Store({ veeValidate, ], modules: { + accounts: accountsModule, invites: invitesModule, permissions: permissionsModule, transactionCache: transactionCacheModule, diff --git a/src/store/plugins/account.js b/src/store/modules/accounts.js similarity index 96% rename from src/store/plugins/account.js rename to src/store/modules/accounts.js index 3a7d0ffca..3f5d4e13e 100644 --- a/src/store/plugins/account.js +++ b/src/store/modules/accounts.js @@ -1,6 +1,6 @@ import { Crypto, TxBuilder, SCHEMA } from '@aeternity/aepp-sdk'; -export default (store) => store.registerModule('accounts', { +export default { namespaced: true, actions: { signWithoutConfirmation({ rootGetters: { account } }, data) { @@ -50,4 +50,4 @@ export default (store) => store.registerModule('accounts', { return TxBuilder.buildTx({ encodedTx, signatures: [signature] }, SCHEMA.TX_TYPE.signed).tx; }, }, -}); +}; From df562aafca6d098e484382562e1f5f8c69acdd07 Mon Sep 17 00:00:00 2001 From: Nikita Cedrik Date: Wed, 1 Sep 2021 11:43:51 +1000 Subject: [PATCH 03/65] refactor(accounts): move account related to the accounts --- src/background/store.js | 3 +- src/background/wallet.js | 2 +- src/lib/wallet.js | 2 +- src/popup/router/components/AccountInfo.vue | 7 ++-- .../router/components/AccountSwitcher.vue | 4 +-- src/popup/router/components/BalanceInfo.vue | 3 +- .../router/components/TransactionList.vue | 2 +- src/popup/router/pages/Accounts.vue | 5 +-- .../pages/FungibleTokens/TokenDetails.vue | 2 +- src/popup/router/pages/TransferSend.vue | 3 +- src/store/getters.js | 4 +-- src/store/index.js | 5 --- src/store/modules/accounts.js | 35 +++++++++++++++++++ src/store/mutations.js | 25 ------------- src/store/plugins/fungibleTokens.js | 2 +- src/store/plugins/names.js | 2 +- src/store/plugins/observables.js | 2 +- src/store/utils.js | 8 ++--- 18 files changed, 61 insertions(+), 55 deletions(-) diff --git a/src/background/store.js b/src/background/store.js index 1ca299092..1ef07a8de 100644 --- a/src/background/store.js +++ b/src/background/store.js @@ -2,13 +2,14 @@ import Vue from 'vue'; import Vuex from 'vuex'; import persistState from '../store/plugins/persistState'; import permissions from '../store/modules/permissions'; +import accounts from '../store/modules/accounts'; import getters from '../store/getters'; Vue.use(Vuex); const store = new Vuex.Store({ plugins: [persistState()], - modules: { permissions }, + modules: { permissions, accounts }, getters: { 'names/getDefault': () => (address) => `placeholder name for ${address}`, wallet: getters.wallet, diff --git a/src/background/wallet.js b/src/background/wallet.js index 9bfac16f0..942ce26f2 100644 --- a/src/background/wallet.js +++ b/src/background/wallet.js @@ -198,7 +198,7 @@ export async function init() { ); store.watch( - ({ accountSelectedIdx }) => accountSelectedIdx, + ({ accounts: { accountSelectedIdx } }) => accountSelectedIdx, async (accountIdx) => sdk.selectAccount(store.getters.accounts[accountIdx].address), ); diff --git a/src/lib/wallet.js b/src/lib/wallet.js index fd3b58503..76c9b7c9a 100644 --- a/src/lib/wallet.js +++ b/src/lib/wallet.js @@ -266,7 +266,7 @@ export default async function initSdk() { }, ); store.watch( - ({ accountSelectedIdx }) => accountSelectedIdx, + ({ accounts: { accountSelectedIdx } }) => accountSelectedIdx, async (accountIdx) => store.commit('selectSdkAccount', store.getters.accounts[accountIdx].address), ); diff --git a/src/popup/router/components/AccountInfo.vue b/src/popup/router/components/AccountInfo.vue index 413fca2e4..d82e5e016 100644 --- a/src/popup/router/components/AccountInfo.vue +++ b/src/popup/router/components/AccountInfo.vue @@ -146,7 +146,8 @@ export default { UNFINISHED_FEATURES: process.env.UNFINISHED_FEATURES, }), computed: { - ...mapState(['accountSelectedIdx', 'cardMinified']), + ...mapState('accounts', ['accountSelectedIdx']), + ...mapState(['cardMinified']), ...mapGetters(['accounts', 'activeNetwork']), idx() { return this.accountIdx === -1 ? this.accountSelectedIdx : this.accountIdx; @@ -165,7 +166,7 @@ export default { this.customAccountName = this.accounts[this.idx].localName; }, methods: { - ...mapMutations(['createAccount', 'deleteAccount']), + ...mapMutations('accounts', ['createAccount', 'deleteAccount']), editLocalName() { this.customAccountName = this.accounts[this.idx].localName; this.edit = true; @@ -175,7 +176,7 @@ export default { this.$store.dispatch('fungibleTokens/loadTokenBalances'); }, saveLocalName() { - this.$store.commit('setAccountLocalName', { name: this.customAccountName, idx: this.idx }); + this.$store.commit('accounts/setAccountLocalName', { name: this.customAccountName, idx: this.idx }); this.edit = false; }, copy() { diff --git a/src/popup/router/components/AccountSwitcher.vue b/src/popup/router/components/AccountSwitcher.vue index 62d362fb8..cbd5de8fc 100644 --- a/src/popup/router/components/AccountSwitcher.vue +++ b/src/popup/router/components/AccountSwitcher.vue @@ -38,7 +38,7 @@ export default { components: { AccountCard, ButtonPlain }, props: { notification: Boolean }, computed: { - ...mapState(['accountSelectedIdx']), + ...mapState('accounts', ['accountSelectedIdx']), ...mapGetters(['accounts']), cssVars() { return { @@ -56,7 +56,7 @@ export default { methods: { async selectAccount(idx) { await this.$watchUntilTruly(() => this.$store.state.middleware); - this.$store.commit('selectAccount', idx); + this.$store.commit('accounts/selectAccount', idx); }, }, }; diff --git a/src/popup/router/components/BalanceInfo.vue b/src/popup/router/components/BalanceInfo.vue index acf032ea6..bcf5c9888 100644 --- a/src/popup/router/components/BalanceInfo.vue +++ b/src/popup/router/components/BalanceInfo.vue @@ -55,7 +55,8 @@ export default { return pick(this.$store.state.observables, ['balances']); }, computed: { - ...mapState(['current', 'currencies', 'accountSelectedIdx']), + ...mapState('accounts', ['accountSelectedIdx']), + ...mapState(['current', 'currencies']), ...mapGetters('fungibleTokens', ['getTokenBalance', 'getSelectedToken']), ...mapGetters(['formatCurrency', 'currentCurrencyRate', 'accounts']), tokenBalancesOptions() { diff --git a/src/popup/router/components/TransactionList.vue b/src/popup/router/components/TransactionList.vue index b3256241e..fc86dc0c8 100644 --- a/src/popup/router/components/TransactionList.vue +++ b/src/popup/router/components/TransactionList.vue @@ -75,7 +75,7 @@ export default { }, computed: { ...mapState('fungibleTokens', ['availableTokens']), - ...mapState(['accountSelectedIdx']), + ...mapState('accounts', ['accountSelectedIdx']), ...mapState({ filteredTransactions(state, { account: { address } }) { const isFungibleTokenTx = (tr) => Object.keys(this.availableTokens) diff --git a/src/popup/router/pages/Accounts.vue b/src/popup/router/pages/Accounts.vue index 59e1e6b8a..4968c2b10 100644 --- a/src/popup/router/pages/Accounts.vue +++ b/src/popup/router/pages/Accounts.vue @@ -36,14 +36,15 @@ export default { computed: mapGetters(['accounts']), methods: { async toggleAccountShowed(isShowed, index) { - if (!isShowed && this.$store.state.accs.reduce((a, b) => (b.showed ? a + 1 : a), 0) === 8) { + if (!isShowed + && this.$store.state.accounts.accs.reduce((a, b) => (b.showed ? a + 1 : a), 0) === 8) { await this.$store.dispatch('modals/open', { name: 'default', title: this.$t('modals.switcherAccsLimit.title'), msg: this.$t('modals.switcherAccsLimit.msg'), }); } else { - this.$store.commit('toggleAccountShowed', index); + this.$store.commit('accounts/toggleAccountShowed', index); } }, }, diff --git a/src/popup/router/pages/FungibleTokens/TokenDetails.vue b/src/popup/router/pages/FungibleTokens/TokenDetails.vue index 140a519d9..102c5fd8a 100644 --- a/src/popup/router/pages/FungibleTokens/TokenDetails.vue +++ b/src/popup/router/pages/FungibleTokens/TokenDetails.vue @@ -146,7 +146,7 @@ export default { }, computed: { ...mapGetters(['tippingSupported', 'formatCurrency', 'accounts']), - ...mapState(['accountSelectedIdx']), + ...mapState('accounts', ['accountSelectedIdx']), ...mapState('fungibleTokens', ['aePublicData', 'availableTokens']), ...mapGetters('fungibleTokens', ['tokenBalances']), fungibleToken() { diff --git a/src/popup/router/pages/TransferSend.vue b/src/popup/router/pages/TransferSend.vue index 8cdd39112..a3bc76c10 100644 --- a/src/popup/router/pages/TransferSend.vue +++ b/src/popup/router/pages/TransferSend.vue @@ -216,8 +216,9 @@ export default { }; }, computed: { + ...mapState('accounts', ['accountSelectedIdx']), ...mapState('fungibleTokens', ['availableTokens']), - ...mapState(['current', 'sdk', 'accountSelectedIdx']), + ...mapState(['current', 'sdk']), ...mapGetters(['account', 'formatCurrency', 'currentCurrencyRate', 'accounts']), ...mapGetters('fungibleTokens', ['selectedToken', 'tokenBalances']), validAddress() { diff --git a/src/store/getters.js b/src/store/getters.js index 272c1a5e2..ca64fc990 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -30,7 +30,7 @@ export default { if (!mnemonic) return null; return generateHdWallet(mnemonicToSeed(mnemonic)); }, - accounts({ accs }, getters) { + accounts({ accounts: { accs } }, getters) { if (!getters.wallet) return []; return accs .map(({ idx, ...acc }) => ({ @@ -46,7 +46,7 @@ export default { localName || (idx === 0 ? i18n.t('mainAccount') : i18n.t('subaccountName', { idx })), })); }, - account({ accountSelectedIdx }, { accounts }) { + account({ accounts: { accountSelectedIdx } }, { accounts }) { return accounts[accountSelectedIdx] || {}; // TODO: Return null }, isLoggedIn: (state, { account }) => Object.keys(account).length > 0, diff --git a/src/store/index.js b/src/store/index.js index daca24d80..630983cdd 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -60,11 +60,6 @@ export default new Vuex.Store({ tourStartBar: true, saveErrorLog: true, loginTargetLocation: { name: 'account' }, - accountCount: 1, - accountSelectedIdx: 0, - accs: [{ - idx: 0, color: '#1161FE', shift: 0, showed: true, - }], cardMinified: false, }, getters, diff --git a/src/store/modules/accounts.js b/src/store/modules/accounts.js index 3f5d4e13e..91b624fad 100644 --- a/src/store/modules/accounts.js +++ b/src/store/modules/accounts.js @@ -1,7 +1,42 @@ +import Vue from 'vue'; import { Crypto, TxBuilder, SCHEMA } from '@aeternity/aepp-sdk'; export default { namespaced: true, + state: { + accs: [{ + idx: 0, color: '#1161FE', shift: 0, showed: true, + }], + accountSelectedIdx: 0, + accountCount: 1, + }, + mutations: { + createAccount(state) { + state.accs.push({ + idx: state.accountCount, + color: + // eslint-disable-next-line no-bitwise + state.accountCount === 1 ? '#00FF9D' : `#${((Math.random() * 0xffffff) << 0).toString(16)}`, + shift: Math.floor(Math.random() * 100), + showed: state.accs.reduce((a, b) => (b.showed ? a + 1 : a), 0) < 8, + }); + state.accountCount += 1; + }, + deleteAccount(state, idx) { + if (state.accountSelectedIdx === idx) state.accountSelectedIdx = 0; + Vue.delete(state.accs, idx); + }, + selectAccount(state, idx) { + state.accountSelectedIdx = idx; + }, + setAccountLocalName(state, { name, idx }) { + Vue.set(state.accs[idx], 'localName', name); + }, + toggleAccountShowed(state, idx) { + if (state.accountSelectedIdx === idx) state.accountSelectedIdx = 0; + Vue.set(state.accs[idx], 'showed', !state.accs[idx].showed); + }, + }, actions: { signWithoutConfirmation({ rootGetters: { account } }, data) { return Crypto.sign(data, account.secretKey); diff --git a/src/store/mutations.js b/src/store/mutations.js index 2a79b1819..3d240c1f1 100644 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -97,31 +97,6 @@ export default { setLoginTargetLocation(state, location) { state.loginTargetLocation = location; }, - createAccount(state) { - state.accs.push({ - idx: state.accountCount, - color: - // eslint-disable-next-line no-bitwise - state.accountCount === 1 ? '#00FF9D' : `#${((Math.random() * 0xffffff) << 0).toString(16)}`, - shift: Math.floor(Math.random() * 100), - showed: state.accs.reduce((a, b) => (b.showed ? a + 1 : a), 0) < 8, - }); - state.accountCount += 1; - }, - deleteAccount(state, idx) { - if (state.accountSelectedIdx === idx) state.accountSelectedIdx = 0; - Vue.delete(state.accs, idx); - }, - selectAccount(state, idx) { - state.accountSelectedIdx = idx; - }, - setAccountLocalName(state, { name, idx }) { - Vue.set(state.accs[idx], 'localName', name); - }, - toggleAccountShowed(state, idx) { - if (state.accountSelectedIdx === idx) state.accountSelectedIdx = 0; - Vue.set(state.accs[idx], 'showed', !state.accs[idx].showed); - }, setSdkAccounts({ sdk }, list) { sdk.accounts = list.reduce((p, { address }) => ({ ...p, [address]: {} }), {}); }, diff --git a/src/store/plugins/fungibleTokens.js b/src/store/plugins/fungibleTokens.js index 0c3480300..d3efe99de 100644 --- a/src/store/plugins/fungibleTokens.js +++ b/src/store/plugins/fungibleTokens.js @@ -221,7 +221,7 @@ export default (store) => { ); store.watch( - ({ accountCount }) => accountCount, + ({ accounts: { accountCount } }) => accountCount, async () => { if (!store.state.middleware) return; await store.dispatch('fungibleTokens/loadTokenBalances'); diff --git a/src/store/plugins/names.js b/src/store/plugins/names.js index 2cab15210..3dc2f2128 100644 --- a/src/store/plugins/names.js +++ b/src/store/plugins/names.js @@ -213,7 +213,7 @@ export default (store) => { ); store.watch( - ({ accountCount }) => accountCount, + ({ accounts: { accountCount } }) => accountCount, async () => { if (!store.state.middleware) return; await store.dispatch('names/fetchOwned'); diff --git a/src/store/plugins/observables.js b/src/store/plugins/observables.js index 2c6650ad0..f2262f325 100644 --- a/src/store/plugins/observables.js +++ b/src/store/plugins/observables.js @@ -53,7 +53,7 @@ export default (store) => { )); const balance$ = watchAsObservable( - ({ accountSelectedIdx }, { accounts }) => accounts[accountSelectedIdx], + ({ accounts: { accountSelectedIdx } }, { accounts }) => accounts[accountSelectedIdx], { immediate: true, }, diff --git a/src/store/utils.js b/src/store/utils.js index d130bfd78..494770293 100644 --- a/src/store/utils.js +++ b/src/store/utils.js @@ -16,9 +16,7 @@ export default ({ notificationSettings, permissions, fungibleTokens, - accountCount, - accountSelectedIdx, - accs, + accounts: { accs, accountSelectedIdx, accountCount } = {}, cardMinified, }) => ({ migrations, @@ -38,8 +36,6 @@ export default ({ notificationSettings, permissions, fungibleTokens, - accountCount, - accountSelectedIdx, - accs, + accounts: { accs, accountSelectedIdx, accountCount }, cardMinified, }); From 9695e681b2d98cd50c94ff432ec5f7e3ae27a305 Mon Sep 17 00:00:00 2001 From: Nikita Cedrik Date: Wed, 1 Sep 2021 12:12:38 +1000 Subject: [PATCH 04/65] refactor(accounts): rename state and mutations --- src/background/wallet.js | 2 +- src/lib/wallet.js | 2 +- src/popup/router/components/AccountInfo.vue | 10 ++--- .../router/components/AccountSwitcher.vue | 18 ++++----- src/popup/router/components/BalanceInfo.vue | 4 +- .../router/components/TransactionList.vue | 4 +- src/popup/router/pages/Accounts.vue | 4 +- .../pages/FungibleTokens/TokenDetails.vue | 4 +- src/popup/router/pages/TransferSend.vue | 4 +- src/store/getters.js | 8 ++-- src/store/modules/accounts.js | 38 +++++++++---------- src/store/plugins/fungibleTokens.js | 2 +- src/store/plugins/names.js | 2 +- src/store/plugins/observables.js | 2 +- src/store/utils.js | 4 +- 15 files changed, 54 insertions(+), 54 deletions(-) diff --git a/src/background/wallet.js b/src/background/wallet.js index 942ce26f2..7d395f462 100644 --- a/src/background/wallet.js +++ b/src/background/wallet.js @@ -198,7 +198,7 @@ export async function init() { ); store.watch( - ({ accounts: { accountSelectedIdx } }) => accountSelectedIdx, + ({ accounts: { activeIdx } }) => activeIdx, async (accountIdx) => sdk.selectAccount(store.getters.accounts[accountIdx].address), ); diff --git a/src/lib/wallet.js b/src/lib/wallet.js index 76c9b7c9a..ca9edfd27 100644 --- a/src/lib/wallet.js +++ b/src/lib/wallet.js @@ -266,7 +266,7 @@ export default async function initSdk() { }, ); store.watch( - ({ accounts: { accountSelectedIdx } }) => accountSelectedIdx, + ({ accounts: { activeIdx } }) => activeIdx, async (accountIdx) => store.commit('selectSdkAccount', store.getters.accounts[accountIdx].address), ); diff --git a/src/popup/router/components/AccountInfo.vue b/src/popup/router/components/AccountInfo.vue index d82e5e016..882ce5455 100644 --- a/src/popup/router/components/AccountInfo.vue +++ b/src/popup/router/components/AccountInfo.vue @@ -146,11 +146,11 @@ export default { UNFINISHED_FEATURES: process.env.UNFINISHED_FEATURES, }), computed: { - ...mapState('accounts', ['accountSelectedIdx']), + ...mapState('accounts', ['activeIdx']), ...mapState(['cardMinified']), ...mapGetters(['accounts', 'activeNetwork']), idx() { - return this.accountIdx === -1 ? this.accountSelectedIdx : this.accountIdx; + return this.accountIdx === -1 ? this.activeIdx : this.accountIdx; }, explorerUrl() { const { address } = this.accounts[this.idx]; @@ -166,7 +166,7 @@ export default { this.customAccountName = this.accounts[this.idx].localName; }, methods: { - ...mapMutations('accounts', ['createAccount', 'deleteAccount']), + ...mapMutations({ createAccount: 'accounts/add' }), editLocalName() { this.customAccountName = this.accounts[this.idx].localName; this.edit = true; @@ -176,7 +176,7 @@ export default { this.$store.dispatch('fungibleTokens/loadTokenBalances'); }, saveLocalName() { - this.$store.commit('accounts/setAccountLocalName', { name: this.customAccountName, idx: this.idx }); + this.$store.commit('accounts/setLocalName', { name: this.customAccountName, idx: this.idx }); this.edit = false; }, copy() { @@ -192,7 +192,7 @@ export default { title: this.$t('modals.removeSubaccount.title'), msg: this.$t('modals.removeSubaccount.msg'), }); - this.deleteAccount(this.idx); + this.$store.commit('accounts/remove', this.idx); }, }, }; diff --git a/src/popup/router/components/AccountSwitcher.vue b/src/popup/router/components/AccountSwitcher.vue index cbd5de8fc..5b29ec849 100644 --- a/src/popup/router/components/AccountSwitcher.vue +++ b/src/popup/router/components/AccountSwitcher.vue @@ -10,7 +10,7 @@ @@ -22,7 +22,7 @@ @@ -38,25 +38,25 @@ export default { components: { AccountCard, ButtonPlain }, props: { notification: Boolean }, computed: { - ...mapState('accounts', ['accountSelectedIdx']), + ...mapState('accounts', ['activeIdx']), ...mapGetters(['accounts']), cssVars() { return { - '--accountSelectedIdx': this.selectedCardNumber, - '--accountCount': this.filteredAccounts.length, + '--activeIdx': this.selectedCardNumber, + '--nextAccountIdx': this.filteredAccounts.length, }; }, filteredAccounts() { return this.accounts.map((a, index) => ({ ...a, i: index })).filter((a) => a.showed); }, selectedCardNumber() { - return this.filteredAccounts.findIndex((a) => a.i === this.accountSelectedIdx); + return this.filteredAccounts.findIndex((a) => a.i === this.activeIdx); }, }, methods: { async selectAccount(idx) { await this.$watchUntilTruly(() => this.$store.state.middleware); - this.$store.commit('accounts/selectAccount', idx); + this.$store.commit('accounts/setActiveIdx', idx); }, }, }; @@ -77,11 +77,11 @@ export default { .cards-wrapper { display: flex; - width: calc(var(--accountCount) * (312px + 8px) + 24px + 24px); + width: calc(var(--nextAccountIdx) * (312px + 8px) + 24px + 24px); align-self: center; margin-bottom: 16px; transition: margin-left 0.5s ease-out; - margin-left: calc(var(--accountSelectedIdx) * (-312px - 8px)); + margin-left: calc(var(--activeIdx) * (-312px - 8px)); .account-card { margin-right: 4px; diff --git a/src/popup/router/components/BalanceInfo.vue b/src/popup/router/components/BalanceInfo.vue index bcf5c9888..602dada59 100644 --- a/src/popup/router/components/BalanceInfo.vue +++ b/src/popup/router/components/BalanceInfo.vue @@ -55,7 +55,7 @@ export default { return pick(this.$store.state.observables, ['balances']); }, computed: { - ...mapState('accounts', ['accountSelectedIdx']), + ...mapState('accounts', ['activeIdx']), ...mapState(['current', 'currencies']), ...mapGetters('fungibleTokens', ['getTokenBalance', 'getSelectedToken']), ...mapGetters(['formatCurrency', 'currentCurrencyRate', 'accounts']), @@ -78,7 +78,7 @@ export default { return this.selectedToken ? this.selectedToken.value : 'default'; }, idx() { - return this.accountIdx === -1 ? this.accountSelectedIdx : this.accountIdx; + return this.accountIdx === -1 ? this.activeIdx : this.accountIdx; }, tokenBalances() { return this.getTokenBalance(this.accounts[this.idx].address); diff --git a/src/popup/router/components/TransactionList.vue b/src/popup/router/components/TransactionList.vue index fc86dc0c8..e95f79f61 100644 --- a/src/popup/router/components/TransactionList.vue +++ b/src/popup/router/components/TransactionList.vue @@ -75,7 +75,7 @@ export default { }, computed: { ...mapState('fungibleTokens', ['availableTokens']), - ...mapState('accounts', ['accountSelectedIdx']), + ...mapState('accounts', ['activeIdx']), ...mapState({ filteredTransactions(state, { account: { address } }) { const isFungibleTokenTx = (tr) => Object.keys(this.availableTokens) @@ -120,7 +120,7 @@ export default { ...mapGetters('transactionCache', ['chainTransactions']), }, watch: { - accountSelectedIdx() { + activeIdx() { this.$store.commit('setTransactions', []); this.transactions = []; this.page = 1; diff --git a/src/popup/router/pages/Accounts.vue b/src/popup/router/pages/Accounts.vue index 4968c2b10..e624a19b3 100644 --- a/src/popup/router/pages/Accounts.vue +++ b/src/popup/router/pages/Accounts.vue @@ -37,14 +37,14 @@ export default { methods: { async toggleAccountShowed(isShowed, index) { if (!isShowed - && this.$store.state.accounts.accs.reduce((a, b) => (b.showed ? a + 1 : a), 0) === 8) { + && this.$store.state.accounts.list.reduce((a, b) => (b.showed ? a + 1 : a), 0) === 8) { await this.$store.dispatch('modals/open', { name: 'default', title: this.$t('modals.switcherAccsLimit.title'), msg: this.$t('modals.switcherAccsLimit.msg'), }); } else { - this.$store.commit('accounts/toggleAccountShowed', index); + this.$store.commit('accounts/toggleShowed', index); } }, }, diff --git a/src/popup/router/pages/FungibleTokens/TokenDetails.vue b/src/popup/router/pages/FungibleTokens/TokenDetails.vue index 102c5fd8a..f3009969b 100644 --- a/src/popup/router/pages/FungibleTokens/TokenDetails.vue +++ b/src/popup/router/pages/FungibleTokens/TokenDetails.vue @@ -146,7 +146,7 @@ export default { }, computed: { ...mapGetters(['tippingSupported', 'formatCurrency', 'accounts']), - ...mapState('accounts', ['accountSelectedIdx']), + ...mapState('accounts', ['activeIdx']), ...mapState('fungibleTokens', ['aePublicData', 'availableTokens']), ...mapGetters('fungibleTokens', ['tokenBalances']), fungibleToken() { @@ -179,7 +179,7 @@ export default { methods: { proceed(path) { this.$store.commit('fungibleTokens/setSelectedToken', { - address: this.accounts[this.accountSelectedIdx].address, + address: this.accounts[this.activeIdx].address, token: this.id !== 'aeternity' ? this.tokenBalances.find(({ value }) => value === this.id) : null, }); this.$router.push(path); diff --git a/src/popup/router/pages/TransferSend.vue b/src/popup/router/pages/TransferSend.vue index a3bc76c10..92edf42b9 100644 --- a/src/popup/router/pages/TransferSend.vue +++ b/src/popup/router/pages/TransferSend.vue @@ -216,7 +216,7 @@ export default { }; }, computed: { - ...mapState('accounts', ['accountSelectedIdx']), + ...mapState('accounts', ['activeIdx']), ...mapState('fungibleTokens', ['availableTokens']), ...mapState(['current', 'sdk']), ...mapGetters(['account', 'formatCurrency', 'currentCurrencyRate', 'accounts']), @@ -276,7 +276,7 @@ export default { // SELECT ZEIT TOKEN this.$store.commit('fungibleTokens/setSelectedToken', { - address: this.accounts[this.accountSelectedIdx].address, + address: this.accounts[this.activeIdx].address, token: this.tokenBalances.find(({ value }) => value === ZEIT_TOKEN_CONTRACT), }); // SET result data diff --git a/src/store/getters.js b/src/store/getters.js index ca64fc990..d3f162701 100644 --- a/src/store/getters.js +++ b/src/store/getters.js @@ -30,9 +30,9 @@ export default { if (!mnemonic) return null; return generateHdWallet(mnemonicToSeed(mnemonic)); }, - accounts({ accounts: { accs } }, getters) { + accounts({ accounts: { list } }, getters) { if (!getters.wallet) return []; - return accs + return list .map(({ idx, ...acc }) => ({ idx, ...acc, @@ -46,8 +46,8 @@ export default { localName || (idx === 0 ? i18n.t('mainAccount') : i18n.t('subaccountName', { idx })), })); }, - account({ accounts: { accountSelectedIdx } }, { accounts }) { - return accounts[accountSelectedIdx] || {}; // TODO: Return null + account({ accounts: { activeIdx } }, { accounts }) { + return accounts[activeIdx] || {}; // TODO: Return null }, isLoggedIn: (state, { account }) => Object.keys(account).length > 0, currentCurrencyRate: ({ current: { currency }, currencies }) => currencies[currency] || 0, diff --git a/src/store/modules/accounts.js b/src/store/modules/accounts.js index 91b624fad..64a2a55fd 100644 --- a/src/store/modules/accounts.js +++ b/src/store/modules/accounts.js @@ -4,37 +4,37 @@ import { Crypto, TxBuilder, SCHEMA } from '@aeternity/aepp-sdk'; export default { namespaced: true, state: { - accs: [{ + list: [{ idx: 0, color: '#1161FE', shift: 0, showed: true, }], - accountSelectedIdx: 0, - accountCount: 1, + activeIdx: 0, + nextAccountIdx: 1, }, mutations: { - createAccount(state) { - state.accs.push({ - idx: state.accountCount, + add(state) { + state.list.push({ + idx: state.nextAccountIdx, color: // eslint-disable-next-line no-bitwise - state.accountCount === 1 ? '#00FF9D' : `#${((Math.random() * 0xffffff) << 0).toString(16)}`, + state.nextAccountIdx === 1 ? '#00FF9D' : `#${((Math.random() * 0xffffff) << 0).toString(16)}`, shift: Math.floor(Math.random() * 100), - showed: state.accs.reduce((a, b) => (b.showed ? a + 1 : a), 0) < 8, + showed: state.list.reduce((a, b) => (b.showed ? a + 1 : a), 0) < 8, }); - state.accountCount += 1; + state.nextAccountIdx += 1; }, - deleteAccount(state, idx) { - if (state.accountSelectedIdx === idx) state.accountSelectedIdx = 0; - Vue.delete(state.accs, idx); + remove(state, idx) { + if (state.activeIdx === idx) state.activeIdx = 0; + Vue.delete(state.list, idx); }, - selectAccount(state, idx) { - state.accountSelectedIdx = idx; + setActiveIdx(state, idx) { + state.activeIdx = idx; }, - setAccountLocalName(state, { name, idx }) { - Vue.set(state.accs[idx], 'localName', name); + setLocalName(state, { name, idx }) { + Vue.set(state.list[idx], 'localName', name); }, - toggleAccountShowed(state, idx) { - if (state.accountSelectedIdx === idx) state.accountSelectedIdx = 0; - Vue.set(state.accs[idx], 'showed', !state.accs[idx].showed); + toggleShowed(state, idx) { + if (state.activeIdx === idx) state.activeIdx = 0; + Vue.set(state.list[idx], 'showed', !state.list[idx].showed); }, }, actions: { diff --git a/src/store/plugins/fungibleTokens.js b/src/store/plugins/fungibleTokens.js index d3efe99de..4634a835a 100644 --- a/src/store/plugins/fungibleTokens.js +++ b/src/store/plugins/fungibleTokens.js @@ -221,7 +221,7 @@ export default (store) => { ); store.watch( - ({ accounts: { accountCount } }) => accountCount, + ({ accounts: { nextAccountIdx } }) => nextAccountIdx, async () => { if (!store.state.middleware) return; await store.dispatch('fungibleTokens/loadTokenBalances'); diff --git a/src/store/plugins/names.js b/src/store/plugins/names.js index 3dc2f2128..16ce61867 100644 --- a/src/store/plugins/names.js +++ b/src/store/plugins/names.js @@ -213,7 +213,7 @@ export default (store) => { ); store.watch( - ({ accounts: { accountCount } }) => accountCount, + ({ accounts: { nextAccountIdx } }) => nextAccountIdx, async () => { if (!store.state.middleware) return; await store.dispatch('names/fetchOwned'); diff --git a/src/store/plugins/observables.js b/src/store/plugins/observables.js index f2262f325..ec89326c7 100644 --- a/src/store/plugins/observables.js +++ b/src/store/plugins/observables.js @@ -53,7 +53,7 @@ export default (store) => { )); const balance$ = watchAsObservable( - ({ accounts: { accountSelectedIdx } }, { accounts }) => accounts[accountSelectedIdx], + ({ accounts: { activeIdx } }, { accounts }) => accounts[activeIdx], { immediate: true, }, diff --git a/src/store/utils.js b/src/store/utils.js index 494770293..07c3b9657 100644 --- a/src/store/utils.js +++ b/src/store/utils.js @@ -16,7 +16,7 @@ export default ({ notificationSettings, permissions, fungibleTokens, - accounts: { accs, accountSelectedIdx, accountCount } = {}, + accounts: { list, activeIdx, nextAccountIdx } = {}, cardMinified, }) => ({ migrations, @@ -36,6 +36,6 @@ export default ({ notificationSettings, permissions, fungibleTokens, - accounts: { accs, accountSelectedIdx, accountCount }, + accounts: { list, activeIdx, nextAccountIdx }, cardMinified, }); From 68bed5ca3367c0ec58539dcbe0d09abd5e9a9483 Mon Sep 17 00:00:00 2001 From: Nikita Cedrik Date: Wed, 1 Sep 2021 13:46:51 +1000 Subject: [PATCH 05/65] refactor(accounts): extract hdWallet module --- src/popup/router/components/AccountInfo.vue | 4 +- .../{accounts.js => accounts/hdWallet.js} | 50 ++++++--------- src/store/modules/accounts/index.js | 62 +++++++++++++++++++ src/store/plugins/fungibleTokens.js | 2 +- src/store/plugins/names.js | 2 +- src/store/utils.js | 4 +- 6 files changed, 87 insertions(+), 37 deletions(-) rename src/store/modules/{accounts.js => accounts/hdWallet.js} (66%) create mode 100644 src/store/modules/accounts/index.js diff --git a/src/popup/router/components/AccountInfo.vue b/src/popup/router/components/AccountInfo.vue index 882ce5455..e666d2c9f 100644 --- a/src/popup/router/components/AccountInfo.vue +++ b/src/popup/router/components/AccountInfo.vue @@ -106,7 +106,7 @@ + <% } %> + + diff --git a/src/background/deeplink-handler.js b/src/background/deeplink-handler.js index 686a83e87..1d1788e80 100644 --- a/src/background/deeplink-handler.js +++ b/src/background/deeplink-handler.js @@ -2,7 +2,7 @@ import { APP_LINK_WEB } from '../popup/utils/constants'; export default () => browser.webRequest.onBeforeRequest.addListener( ({ url }) => ({ - redirectUrl: browser.runtime.getURL(`/popup/popup.html#${url.replace(APP_LINK_WEB, '')}`), + redirectUrl: browser.runtime.getURL(`/index.html#${url.replace(APP_LINK_WEB, '')}`), }), { urls: [`${APP_LINK_WEB}/*`], diff --git a/src/background/index.js b/src/background/index.js index 484ef2b56..71cb96d0a 100644 --- a/src/background/index.js +++ b/src/background/index.js @@ -13,7 +13,7 @@ RedirectChainNames.init(); initDeeplinkHandler(); const openTipPopup = (pageUrl) => browser.windows.create({ - url: browser.extension.getURL(`./popup/popup.html#/tips?url=${encodeURIComponent(pageUrl)}`), + url: browser.extension.getURL(`./index.html#/tips?url=${encodeURIComponent(pageUrl)}`), type: 'popup', height: 600, width: 375, @@ -71,7 +71,7 @@ browser.webNavigation.onHistoryStateUpdated.addListener(async ({ tabId, url }) = if ( (({ origin, pathname }) => origin + pathname)(new URL(url)) !== 'https://www.youtube.com/watch' ) return; - browser.tabs.executeScript(tabId, { file: 'other/youtube.js' }); + browser.tabs.executeScript(tabId, { file: 'js/youtube.js' }); }); browser.contextMenus.removeAll(); diff --git a/src/background/redirect-chain-names.js b/src/background/redirect-chain-names.js index b24514548..136e8a30a 100644 --- a/src/background/redirect-chain-names.js +++ b/src/background/redirect-chain-names.js @@ -32,7 +32,7 @@ export default { browser.webRequest.onBeforeRequest.addListener( (requestDetails) => { - chrome.tabs.update({ url: '/redirect/index.html' }, async () => { + chrome.tabs.update({ url: '/redirect.html' }, async () => { try { const url = new URL(requestDetails.url); const host = url.hostname; @@ -46,7 +46,7 @@ export default { const displayUrl = `${AGGREGATOR_URL}user-profile/${pubKey}`; chrome.tabs.update({ url: displayUrl }); } catch (err) { - chrome.tabs.update({ url: `/redirect/index.html?error=${err.message}` }); + chrome.tabs.update({ url: `/redirect.html?error=${err.message}` }); } }); return { cancel: true }; diff --git a/src/background/wallet.js b/src/background/wallet.js index 7d395f462..2697f62eb 100644 --- a/src/background/wallet.js +++ b/src/background/wallet.js @@ -28,7 +28,7 @@ const showPopup = async (aepp, type, params) => { } }); - const extUrl = browser.runtime.getURL('./popup/popup.html'); + const extUrl = browser.runtime.getURL('./index.html'); const popupUrl = `${extUrl}?id=${id}&type=${type}&url=${encodeURIComponent(href)}`; const popupWindow = await browser.windows.create({ url: popupUrl, diff --git a/src/manifest.js b/src/manifest.js deleted file mode 100644 index a6355f8aa..000000000 --- a/src/manifest.js +++ /dev/null @@ -1,68 +0,0 @@ -module.exports = (isProd) => ({ - name: 'Superhero', - description: 'Superhero Wallet', - version: process.env.npm_package_version, - manifest_version: 2, - applications: { - gecko: { - strict_min_version: '53.0', - }, - }, - permissions: [ - 'storage', - 'unlimitedStorage', - 'videoCapture', - 'activeTab', - 'clipboardWrite', - ...process.env.UNFINISHED_FEATURES ? ['clipboardRead'] : [], - 'contextMenus', - 'notifications', - 'tabs', - 'webRequest', - 'webRequestBlocking', - 'webNavigation', - '*://*.chain/*', - '*://*.google.com/*', - 'https://*.twitter.com/*', - 'https://twitter.com/*', - 'https://*.youtube.com/watch?v=*', - 'https://wallet.superhero.com/*', - ], - icons: { - 48: './icons/icon_48.png', - 128: './icons/icon_128.png', - }, - content_security_policy: `script-src 'self'${isProd ? '' : " 'unsafe-eval'"}; object-src 'self'`, - browser_action: { - default_title: 'Superhero', - default_popup: 'popup/popup.html', - }, - background: { - scripts: ['background.js'], - persistent: true, - }, - content_scripts: [ - { - run_at: 'document_start', - all_frames: true, - matches: ['https://*/*', 'http://*/*'], - js: ['other/inject.js'], - }, - { - run_at: 'document_start', - matches: ['https://*.twitter.com/*', 'https://twitter.com/*'], - js: ['other/twitter.js'], - }, - { - run_at: 'document_start', - matches: ['https://*.youtube.com/watch?v=*'], - js: ['other/youtube.js'], - }, - ], - web_accessible_resources: [ - 'inject.js', - 'popup/CameraRequestPermission.html', - 'other/tipButton.css', - 'popup/popup.html', - ], -}); diff --git a/src/manifest.json b/src/manifest.json new file mode 100644 index 000000000..630b4c3df --- /dev/null +++ b/src/manifest.json @@ -0,0 +1,65 @@ +{ + "name": "Superhero", + "description": "Superhero Wallet", + "manifest_version": 2, + "applications": { + "gecko": { + "strict_min_version": "53.0" + } + }, + "permissions": [ + "storage", + "unlimitedStorage", + "videoCapture", + "activeTab", + "clipboardWrite", + "contextMenus", + "notifications", + "tabs", + "webRequest", + "webRequestBlocking", + "webNavigation", + "*://*.chain/*", + "*://*.google.com/*", + "https://*.twitter.com/*", + "https://twitter.com/*", + "https://*.youtube.com/watch?v=*", + "https://wallet.superhero.com/*" + ], + "icons": { + "48": "./icons/icon_48.png", + "128": "./icons/icon_128.png" + }, + "browser_action": { + "default_title": "Superhero", + "default_popup": "index.html" + }, + "background": { + "scripts": ["js/background.js"], + "persistent": true + }, + "content_scripts": [ + { + "run_at": "document_start", + "all_frames": true, + "matches": ["https://*/*", "http://*/*"], + "js": ["js/inject.js"] + }, + { + "run_at": "document_start", + "matches": ["https://*.twitter.com/*", "https://twitter.com/*"], + "js": ["js/twitter.js"] + }, + { + "run_at": "document_start", + "matches": ["https://*.youtube.com/watch?v=*"], + "js": ["js/youtube.js"] + } + ], + "web_accessible_resources": [ + "js/inject.js", + "CameraRequestPermission.html", + "other/tipButton.css", + "index.html" + ] +} diff --git a/src/popup/CameraRequestPermission.html b/src/popup/CameraRequestPermission.html index be50ed8f9..f68e43af6 100644 --- a/src/popup/CameraRequestPermission.html +++ b/src/popup/CameraRequestPermission.html @@ -8,9 +8,8 @@ - - \ No newline at end of file diff --git a/src/popup/popup.html b/src/popup/popup.html deleted file mode 100644 index b0e2a24cb..000000000 --- a/src/popup/popup.html +++ /dev/null @@ -1,21 +0,0 @@ - - - - - Superhero Wallet - - - <% if (PLATFORM === 'web') { %> - - - - <% } %> - - -
- - <% if (PLATFORM === 'cordova') { %> - - <% } %> - - diff --git a/src/popup/router/components/Modals/QrCodeReader.vue b/src/popup/router/components/Modals/QrCodeReader.vue index 17442af94..0c99fc583 100644 --- a/src/popup/router/components/Modals/QrCodeReader.vue +++ b/src/popup/router/components/Modals/QrCodeReader.vue @@ -78,7 +78,7 @@ export default { await new Promise((resolve, reject) => { if (process.env.IS_EXTENSION) { window.open( - browser.extension.getURL('./popup/CameraRequestPermission.html'), + browser.extension.getURL('./CameraRequestPermission.html'), '_blank', ); reject(); diff --git a/src/popup/router/pages/TipsSend.vue b/src/popup/router/pages/TipsSend.vue index 5407edcbe..ff0e893cb 100644 --- a/src/popup/router/pages/TipsSend.vue +++ b/src/popup/router/pages/TipsSend.vue @@ -214,7 +214,7 @@ export default { await this.persistTipDetails(); if (process.env.IS_EXTENSION) { const [{ url }] = await browser.tabs.query({ active: true, currentWindow: true }); - this.tipFromPopup = url.includes(browser.runtime.getURL('popup/popup.html')); + this.tipFromPopup = url.includes(browser.runtime.getURL('index.html')); if (url && !this.tipFromPopup) { this.url = url; } else if (this.tipFromPopup) { diff --git a/src/popup/utils/helper.js b/src/popup/utils/helper.js index b3a1ab74d..cc6395286 100644 --- a/src/popup/utils/helper.js +++ b/src/popup/utils/helper.js @@ -35,7 +35,7 @@ export const validateTipUrl = (urlAsString) => { export const detectConnectionType = (port) => { const extensionProtocol = detect().name === 'firefox' ? 'moz-extension' : 'chrome-extension'; const [senderUrl] = port.sender.url.split('?'); - const isExtensionSender = senderUrl.startsWith(`${extensionProtocol}://${browser.runtime.id}/popup/popup.html`) + const isExtensionSender = senderUrl.startsWith(`${extensionProtocol}://${browser.runtime.id}/index.html`) || detect().name === 'firefox'; if (CONNECTION_TYPES.POPUP === port.name && isExtensionSender) { return port.name; diff --git a/src/redirect/redirect.html b/src/redirect/redirect.html index 62bdbb003..369a8a470 100644 --- a/src/redirect/redirect.html +++ b/src/redirect/redirect.html @@ -5,11 +5,8 @@ Superhero Redirect -
- - \ No newline at end of file diff --git a/src/store/plugins/persistState.js b/src/store/plugins/persistState.js index 133015157..e98d3e5d7 100644 --- a/src/store/plugins/persistState.js +++ b/src/store/plugins/persistState.js @@ -27,7 +27,7 @@ export default ( await browser.storage.local.clear(); if (process.env.IS_EXTENSION) browser.runtime.sendMessage({ method: 'reload' }); const location = { - extension: './popup.html', + extension: './index.html', cordova: './index.html', web: '/', }[process.env.PLATFORM]; diff --git a/src/styles/typography.scss b/src/styles/typography.scss index 288bf6d9d..a11759ae3 100644 --- a/src/styles/typography.scss +++ b/src/styles/typography.scss @@ -4,7 +4,7 @@ @import '~fontsource-ibm-plex-sans/500-normal.css'; @import '~fontsource-ibm-plex-sans/700-normal.css'; @import '~fontsource-ibm-plex-sans/700-italic.css'; -@import '@fontsource/ibm-plex-mono/500.css'; +@import '~@fontsource/ibm-plex-mono/500.css'; @import 'variables'; %face-sans-20-bold { diff --git a/tests/.eslintrc.js b/tests/.eslintrc.js deleted file mode 100644 index 96dc0ae08..000000000 --- a/tests/.eslintrc.js +++ /dev/null @@ -1,12 +0,0 @@ -module.exports = { - plugins: ['cypress'], - extends: ['plugin:cypress/recommended'], - env: { - 'cypress/globals': true, - }, - settings: { - 'import/resolver': { - node: {}, - }, - }, -}; diff --git a/tests/e2e/.eslintrc.js b/tests/e2e/.eslintrc.js new file mode 100644 index 000000000..25e20e8c6 --- /dev/null +++ b/tests/e2e/.eslintrc.js @@ -0,0 +1,12 @@ +module.exports = { + plugins: [ + 'cypress', + ], + env: { + mocha: true, + 'cypress/globals': true, + }, + rules: { + strict: 'off', + }, +}; diff --git a/vue.config.js b/vue.config.js new file mode 100644 index 000000000..d3a6ef85e --- /dev/null +++ b/vue.config.js @@ -0,0 +1,198 @@ +const path = require('path'); +const CopyWebpackPlugin = require('copy-webpack-plugin'); +const commitHash = require('child_process').execSync('git rev-parse HEAD').toString().trim(); +const sass = require('sass'); + +// eslint-disable-next-line camelcase +const { npm_package_version, PLATFORM, NODE_ENV } = process.env; + +const parseBool = (val) => (val ? JSON.parse(val) : false); + +const RUNNING_IN_TESTS = parseBool(process.env.RUNNING_IN_TESTS); +const UNFINISHED_FEATURES = parseBool(process.env.UNFINISHED_FEATURES); +const IS_CORDOVA = PLATFORM === 'cordova'; + +module.exports = { + publicPath: { web: '/', extension: '../' }[PLATFORM] || './', + outputDir: { + extension: 'dist/extension', + cordova: 'www', + web: 'dist/web/root', + }[PLATFORM], + productionSourceMap: false, + + pages: { + popup: { + template: 'public/index.html', + entry: 'src/popup/popup.js', + title: 'Popup', + filename: 'index.html', + }, + ...PLATFORM === 'extension' && { + override: { + template: 'src/redirect/redirect.html', + entry: 'src/redirect/redirect.js', + title: 'redirect', + filename: 'redirect.html', + }, + permissions: { + template: 'src/popup/CameraRequestPermission.html', + entry: 'src/popup/cameraPermission.js', + title: 'cameraPermissions', + filename: 'CameraRequestPermission.html', + }, + }, + }, + + pluginOptions: { + ...PLATFORM === 'extension' && { + browserExtension: { + components: { + background: true, + popup: true, + override: true, + contentScripts: true, + }, + componentOptions: { + background: { + entry: 'src/background/index.js', + }, + override: { + entry: 'src/redirect/redirect.js', + }, + contentScripts: { + entries: { + inject: 'src/content-scripts/inject.js', + twitter: 'src/content-scripts/twitter.js', + youtube: 'src/content-scripts/youtube.js', + }, + }, + }, + manifestTransformer: (manifest) => { + manifest.permissions.push(...UNFINISHED_FEATURES ? ['clipboardRead'] : []); + return manifest; + }, + }, + }, + i18n: { + locale: 'en', + fallbackLocale: 'en', + localeDir: 'locales', + enableInSFC: false, + }, + }, + + chainWebpack: (config) => { + config.plugin('define').tap((options) => { + const definitions = { ...options[0] }; + + Object.entries(definitions['process.env']).forEach(([k, v]) => { + definitions[`process.env.${k}`] = v; + }); + delete definitions['process.env']; + + definitions['process.env.UNFINISHED_FEATURES'] = UNFINISHED_FEATURES; + + // eslint-disable-next-line camelcase + if (npm_package_version) { + definitions['process.env.npm_package_version'] = JSON.stringify(npm_package_version); + } + definitions['process.env.NODE_ENV'] = JSON.stringify(NODE_ENV); + definitions['process.env.PLATFORM'] = JSON.stringify(PLATFORM); + definitions['process.env.IS_EXTENSION'] = PLATFORM === 'extension' && !RUNNING_IN_TESTS; + definitions['process.env.RUNNING_IN_TESTS'] = RUNNING_IN_TESTS; + definitions['process.env.COMMIT_HASH'] = JSON.stringify(commitHash); + definitions['process.env.NETWORK'] = JSON.stringify(process.env.NETWORK); + definitions['process.env.IS_CORDOVA'] = IS_CORDOVA; + + return [definitions]; + }).end(); + if (PLATFORM === 'extension' || PLATFORM === 'web') { + config.plugin('copy') + .use(CopyWebpackPlugin, [{ + patterns: [ + ...(PLATFORM === 'web' + ? [ + { from: 'src/web', to: 'dist/web/' }, + ] + : [ + { from: 'public/favicons/favicon-48.png', to: 'icons/icon_48.png' }, + { from: 'public/favicons/favicon-128.png', to: 'icons/icon_128.png' }, + { from: 'public/favicons/request_permission.jpg', to: 'icons/request_permission.jpg' }, + { + from: 'src/content-scripts/tipButton.scss', + to: 'other/tipButton.css', + transform: (_, f) => sass.renderSync({ file: f }).css.toString(), + }]), + ], + }]) + .end(); + } + + if (PLATFORM !== 'extension') { + config.plugins.delete('provide-webextension-polyfill'); + config.plugins.delete('copy-manifest'); + config.module.rules.delete('provide-webextension-polyfill'); + config.plugins.delete('extension-reloader'); + } + config.resolve.alias + .delete('@') + .set('core-js-pure', 'core-js') + .set('lodash', 'lodash-es') + .parent.parent + .module + .rule('aes') + .test(/\.aes$/) + .use('raw-loader') + .loader('raw-loader') + .end(); + + config.module.rule('svg') + .uses.clear().end() + .oneOf('vue-component') + .resourceQuery(/vue-component/) + .use('babel-loader') + .loader('babel-loader') + .options({ configFile: false, presets: ['@babel/preset-env'] }) + .end() + .use('vue-svg-loader') + .loader('vue-svg-loader') + .options({ + svgo: { + plugins: [{ + addClassesToSVGElement: { + type: 'full', + fn(data, options, extra) { + const svg = data.content[0]; + svg.class.add('icon', path.basename(extra.path, '.svg')); + return data; + }, + }, + }], + }, + }) + .end() + .end() + .oneOf('skip-optimize') + .resourceQuery(/skip-optimize/) + .use('vue-svg-loader') + .loader('vue-svg-loader') + .options({ svgo: false }) + .end() + .end() + .oneOf('default') + .use('svg-url-loader') + .loader('svg-url-loader') + .options({ + noquotes: true, + name: 'img/[name].[hash:8].[ext]', + }) + .end() + .use('svgo-loader') + .loader('svgo-loader') + .end(); + return config; + }, + + transpileDependencies: ['@aeternity/hd-wallet', '@download/blockies'], +}; diff --git a/webpack.config.js b/webpack.config.js deleted file mode 100644 index 8eb43a0a6..000000000 --- a/webpack.config.js +++ /dev/null @@ -1,195 +0,0 @@ -const path = require('path'); -const webpack = require('webpack'); -const ejs = require('ejs'); -const MiniCssExtractPlugin = require('mini-css-extract-plugin'); -const CopyWebpackPlugin = require('copy-webpack-plugin'); -const { CleanWebpackPlugin } = require('clean-webpack-plugin'); -const ChromeExtensionReloader = require('webpack-chrome-extension-reloader'); -const { VueLoaderPlugin } = require('vue-loader'); -const GenerateJsonPlugin = require('generate-json-webpack-plugin'); -const TerserPlugin = require('terser-webpack-plugin') -const commitHash = require('child_process').execSync('git rev-parse HEAD').toString().trim(); -const sass = require('sass'); -const genManifest = require('./src/manifest'); - -const parseBool = (val) => (val ? JSON.parse(val) : false); -const RUNNING_IN_TESTS = parseBool(process.env.RUNNING_IN_TESTS); - -const getConfig = (platform) => { - const transformHtml = (content) => - ejs.render(content.toString(), { ...process.env, PLATFORM: platform }); - - return { - mode: process.env.NODE_ENV, - context: path.resolve(__dirname, 'src'), - entry: { - ...(platform === 'extension' && { - background: './background/index.js', - 'other/inject': './content-scripts/inject.js', - 'other/twitter': './content-scripts/twitter.js', - 'other/youtube': './content-scripts/youtube.js', - 'popup/popup': './popup/popup.js', - 'popup/cameraPermission': './popup/cameraPermission.js', - 'redirect/redirect': './redirect/redirect.js', - }), - ...(['cordova', 'web'].includes(platform) && { popup: './popup/popup.js' }), - ...(platform === 'aepp' && { aepp: '../tests/aepp/aepp.js' }), - }, - node: { fs: 'empty', net: 'empty', tls: 'empty' }, - ...platform === 'extension' && { - optimization: { - minimizer: [ - new TerserPlugin({ terserOptions: { output: { ascii_only: true } } }), - ], - }, - }, - output: { - filename: '[name].js', - publicPath: { web: '/', extension: '../' }[platform] || './', - path: path.resolve( - __dirname, - { - extension: 'dist/extension', - cordova: 'www', - web: 'dist/web/root', - aepp: 'dist/aepp', - }[platform], - ), - }, - resolve: { - extensions: ['.js', '.vue'], - }, - module: { - rules: [ - { - test: /\.vue$/, - loaders: 'vue-loader', - }, - { - test: /\.js$/, - loader: 'babel-loader', - exclude: /node_modules/, - }, - { - test: /\.css$/, - use: [MiniCssExtractPlugin.loader, 'css-loader'], - }, - { - test: /\.scss$/, - use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'], - }, - { - test: /\.(png|jpg|gif|svg|ico|woff2|woff)$/, - oneOf: [ - { - test: /\.svg$/, - resourceQuery: /vue-component/, - loader: 'vue-svg-loader', - }, - { - test: /\.svg$/, - resourceQuery: /skip-optimize/, - loader: 'vue-svg-loader', - options: { svgo: false }, - }, - { - loader: 'url-loader', - options: { - name: '[name].[contenthash].[ext]', - esModule: false, - limit: 4096, - outputPath: 'assets/', - }, - }, - ], - }, - ], - }, - stats: { - entrypoints: false, - children: false, - }, - plugins: [ - new CleanWebpackPlugin({ - cleanStaleWebpackAssets: false, - }), - new VueLoaderPlugin(), - new MiniCssExtractPlugin({ - filename: '[name].css', - chunkFilename: '[id].css', - ignoreOrder: false, - }), - new webpack.DefinePlugin({ - global: 'window', - 'process.env': { - NODE_ENV: JSON.stringify(process.env.NODE_ENV), - // TODO: Use PLATFORM === 'extension' comparison instead - IS_EXTENSION: platform === 'extension' && !RUNNING_IN_TESTS, - PLATFORM: JSON.stringify(platform), - npm_package_version: JSON.stringify(process.env.npm_package_version), - NETWORK: JSON.stringify(process.env.NETWORK), - RUNNING_IN_TESTS, - COMMIT_HASH: JSON.stringify(commitHash), - UNFINISHED_FEATURES: JSON.stringify(process.env.SHOW_UNFINISHED_FEATURES), - }, - }), - ...(platform === 'extension' - ? [ - new GenerateJsonPlugin( - 'manifest.json', - genManifest(process.env.NODE_ENV === 'production', platform), - null, - 2, - ), - ] - : []), - ...(process.env.HMR === 'true' && !process.env.RUNNING_IN_TESTS && platform === 'extension' - ? [new ChromeExtensionReloader({ port: 9099 })] - : []), - new CopyWebpackPlugin({ - patterns: [ - ...(platform === 'extension' - ? [ - { from: 'popup/popup.html', to: `popup/popup.html`, transform: transformHtml }, - { - from: 'popup/CameraRequestPermission.html', - to: `popup/CameraRequestPermission.html`, - transform: transformHtml, - }, - { - from: 'redirect/redirect.html', - to: `redirect/index.html`, - transform: transformHtml, - }, - { from: 'icons/icon_48.png', to: `icons/icon_48.png` }, - { from: 'icons/icon_128.png', to: `icons/icon_128.png` }, - { from: 'icons/request_permission.jpg', to: `icons/request_permission.jpg` }, - { - from: 'content-scripts/tipButton.scss', - to: 'other/tipButton.css', - transform: (_, f) => sass.renderSync({ file: f }).css.toString(), - }, - ] - : []), - ...(['cordova', 'web'].includes(platform) - ? [{ from: 'popup/popup.html', to: `index.html`, transform: transformHtml }] - : []), - ...(platform === 'web' - ? [ - { from: 'web', to: `../` }, - { from: 'popup/popup.html', to: `404.html`, transform: transformHtml }, - ] - : []), - ...(platform === 'aepp' - ? [{ from: '../tests/aepp/aepp.html', to: `aepp.html`, transform: transformHtml }] - : []), - ], - }), - ], - }; -}; - -module.exports = (process.env.RUNNING_IN_TESTS - ? ['extension', 'aepp'] - : ['extension', 'cordova', 'web'] -).map((p) => getConfig(p)); From 183d56addcc130e1114dec9416f0708c07339941 Mon Sep 17 00:00:00 2001 From: Nikita Cedrik Date: Mon, 27 Sep 2021 17:23:00 +1000 Subject: [PATCH 13/65] test: update test due to work with web version --- cypress.json | 5 +- package-lock.json | 243 ------------------------------ package.json | 2 - tests/e2e/integration/networks.js | 4 +- tests/e2e/integration/other.js | 2 +- tests/e2e/integration/withdraw.js | 2 +- tests/e2e/plugins/index.js | 46 +----- tests/e2e/support/commands.js | 16 +- 8 files changed, 21 insertions(+), 299 deletions(-) diff --git a/cypress.json b/cypress.json index d76266281..452efb052 100644 --- a/cypress.json +++ b/cypress.json @@ -2,8 +2,6 @@ "pluginsFile": "tests/e2e/plugins/index.js", "userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile/14E5239e Safari/602.1", "video": false, - "baseUrl": "http://localhost:4999/", - "popupUrl": "http://localhost:4999/extension/popup", "viewportWidth": 400, "viewportHeight": 660, "numTestsKeptInMemory": 1, @@ -11,6 +9,7 @@ "defaultCommandTimeout": 30000, "ignoreTestFiles": [ "tip.js", - "transaction-details.js" + "transaction-details.js", + "aex2-popups.js" ] } diff --git a/package-lock.json b/package-lock.json index 7b1da3e86..4c545c466 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2169,34 +2169,6 @@ } } }, - "@cypress/webpack-preprocessor": { - "version": "5.9.1", - "resolved": "https://registry.npmjs.org/@cypress/webpack-preprocessor/-/webpack-preprocessor-5.9.1.tgz", - "integrity": "sha512-cg1ikftIo7NdlRA8ocNSxWjHJlh1JlTkN9ZfXUuKWWcJgrEdYLjXk0UzY6gYbLLaFka4oIhN6SvL5Y/7iELvgg==", - "dev": true, - "requires": { - "bluebird": "^3.7.1", - "debug": "4.3.2", - "lodash": "^4.17.20" - }, - "dependencies": { - "debug": { - "version": "4.3.2", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.2.tgz", - "integrity": "sha512-mOp8wKcvj7XxC78zLgw/ZA+6TSgkoE2C/ienthhRD298T7UNwAg9diBpLRxC0mOezLl4B0xV7M0cCO6P/O0Xhw==", - "dev": true, - "requires": { - "ms": "2.1.2" - } - }, - "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true - } - } - }, "@cypress/xvfb": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/@cypress/xvfb/-/xvfb-1.2.4.tgz", @@ -3260,35 +3232,6 @@ "any-observable": "^0.3.0" } }, - "@sideway/address": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/@sideway/address/-/address-4.1.2.tgz", - "integrity": "sha512-idTz8ibqWFrPU8kMirL0CoPH/A29XOzzAzpyN3zQ4kAWnzmNfFmRaoMNN6VI8ske5M73HZyhIaW4OuSFIdM4oA==", - "dev": true, - "requires": { - "@hapi/hoek": "^9.0.0" - }, - "dependencies": { - "@hapi/hoek": { - "version": "9.2.1", - "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-9.2.1.tgz", - "integrity": "sha512-gfta+H8aziZsm8pZa0vj04KO6biEiisppNgA1kbJvFrrWu9Vm7eaUEy76DIxsuTaWvti5fkJVhllWc6ZTE+Mdw==", - "dev": true - } - } - }, - "@sideway/formula": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@sideway/formula/-/formula-3.0.0.tgz", - "integrity": "sha512-vHe7wZ4NOXVfkoRb8T5otiENVlT7a3IAiw7H5M2+GO+9CDgcVUUsX1zalAztCmwyOr2RUTGJdgB+ZvSVqmdHmg==", - "dev": true - }, - "@sideway/pinpoint": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@sideway/pinpoint/-/pinpoint-2.0.0.tgz", - "integrity": "sha512-RNiOoTPkptFtSVzQevY/yWtZwf/RxyVnPy/OcA9HBM3MlGDnBEYL5B41H0MTn0Uec8Hi+2qUtTfG2WWZBmMejQ==", - "dev": true - }, "@sindresorhus/is": { "version": "0.14.0", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.14.0.tgz", @@ -12037,32 +11980,6 @@ "integrity": "sha512-z7IyloorXvKbFx9Bpie2+vMJKKx1fH1EN5yiTfp8CiLOTptSYy1g8H4yDpGlEdshL1PBiFtBHepF2cNsqeEeFQ==", "dev": true }, - "event-stream": { - "version": "3.3.4", - "resolved": "https://registry.npmjs.org/event-stream/-/event-stream-3.3.4.tgz", - "integrity": "sha1-SrTJoPWlTbkzi0w02Gv86PSzVXE=", - "dev": true, - "requires": { - "duplexer": "~0.1.1", - "from": "~0", - "map-stream": "~0.1.0", - "pause-stream": "0.0.11", - "split": "0.3", - "stream-combiner": "~0.0.4", - "through": "~2.3.1" - }, - "dependencies": { - "split": { - "version": "0.3.3", - "resolved": "https://registry.npmjs.org/split/-/split-0.3.3.tgz", - "integrity": "sha1-zQ7qXmOiEd//frDwkcQTPi0N0o8=", - "dev": true, - "requires": { - "through": "2" - } - } - } - }, "eventemitter2": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/eventemitter2/-/eventemitter2-4.1.2.tgz", @@ -12915,12 +12832,6 @@ "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=", "dev": true }, - "from": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/from/-/from-0.1.7.tgz", - "integrity": "sha1-g8YK/Fi5xWmXAH7Rp2izqzA6RP4=", - "dev": true - }, "from2": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/from2/-/from2-2.3.0.tgz", @@ -17759,36 +17670,6 @@ } } }, - "joi": { - "version": "17.4.2", - "resolved": "https://registry.npmjs.org/joi/-/joi-17.4.2.tgz", - "integrity": "sha512-Lm56PP+n0+Z2A2rfRvsfWVDXGEWjXxatPopkQ8qQ5mxCEhwHG+Ettgg5o98FFaxilOxozoa14cFhrE/hOzh/Nw==", - "dev": true, - "requires": { - "@hapi/hoek": "^9.0.0", - "@hapi/topo": "^5.0.0", - "@sideway/address": "^4.1.0", - "@sideway/formula": "^3.0.0", - "@sideway/pinpoint": "^2.0.0" - }, - "dependencies": { - "@hapi/hoek": { - "version": "9.2.1", - "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-9.2.1.tgz", - "integrity": "sha512-gfta+H8aziZsm8pZa0vj04KO6biEiisppNgA1kbJvFrrWu9Vm7eaUEy76DIxsuTaWvti5fkJVhllWc6ZTE+Mdw==", - "dev": true - }, - "@hapi/topo": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/@hapi/topo/-/topo-5.1.0.tgz", - "integrity": "sha512-foQZKJig7Ob0BMAYBfcJk8d77QtOe7Wo4ox7ff1lQYoNNAb6jwcY1ncdoy2e9wQZzvNy7ODZCYJkK8kzmcAnAg==", - "dev": true, - "requires": { - "@hapi/hoek": "^9.0.0" - } - } - } - }, "joi-browser": { "version": "13.4.0", "resolved": "https://registry.npmjs.org/joi-browser/-/joi-browser-13.4.0.tgz", @@ -19129,12 +19010,6 @@ "integrity": "sha512-+WA2/1sPmDj1dlvvJmB5G6JKfY9dpn7EVBUL06+y6PoljPkh+6V1QihwxNkbcGxCRjt2b0F9K0taiCuo7MbdFQ==", "dev": true }, - "map-stream": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/map-stream/-/map-stream-0.1.0.tgz", - "integrity": "sha1-5WqpTEyAVaFkBKBnS3jyFffI4ZQ=", - "dev": true - }, "map-visit": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/map-visit/-/map-visit-1.0.0.tgz", @@ -21310,15 +21185,6 @@ "integrity": "sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==", "dev": true }, - "pause-stream": { - "version": "0.0.11", - "resolved": "https://registry.npmjs.org/pause-stream/-/pause-stream-0.0.11.tgz", - "integrity": "sha1-/lo0sMvOErWqaitAPuLnO2AvFEU=", - "dev": true, - "requires": { - "through": "~2.3" - } - }, "pbkdf2": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.1.2.tgz", @@ -22673,15 +22539,6 @@ "integrity": "sha1-0/wRS6BplaRexok/SEzrHXj19HY=", "dev": true }, - "ps-tree": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/ps-tree/-/ps-tree-1.2.0.tgz", - "integrity": "sha512-0VnamPPYHl4uaU/nSFeZZpR21QAWRz+sRv4iW9+v/GS/J5U5iZB5BNN6J0RMoOvdx2gWM2+ZFMIm58q24e4UYA==", - "dev": true, - "requires": { - "event-stream": "=3.3.4" - } - }, "pseudomap": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/pseudomap/-/pseudomap-1.0.2.tgz", @@ -25597,67 +25454,6 @@ } } }, - "start-server-and-test": { - "version": "1.12.5", - "resolved": "https://registry.npmjs.org/start-server-and-test/-/start-server-and-test-1.12.5.tgz", - "integrity": "sha512-8Wl0J1xwTDhvWoFeXLIP1VyT9GS5i0XG2440gbMQDNgyCBpb+t2XhahY3ysHIs2g5sDsiom6Iyvh3uQtNrAg5g==", - "dev": true, - "requires": { - "bluebird": "3.7.2", - "check-more-types": "2.24.0", - "debug": "4.3.1", - "execa": "5.1.1", - "lazy-ass": "1.6.0", - "ps-tree": "1.2.0", - "wait-on": "5.3.0" - }, - "dependencies": { - "debug": { - "version": "4.3.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", - "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==", - "dev": true, - "requires": { - "ms": "2.1.2" - } - }, - "execa": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz", - "integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==", - "dev": true, - "requires": { - "cross-spawn": "^7.0.3", - "get-stream": "^6.0.0", - "human-signals": "^2.1.0", - "is-stream": "^2.0.0", - "merge-stream": "^2.0.0", - "npm-run-path": "^4.0.1", - "onetime": "^5.1.2", - "signal-exit": "^3.0.3", - "strip-final-newline": "^2.0.0" - } - }, - "get-stream": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", - "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==", - "dev": true - }, - "human-signals": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", - "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", - "dev": true - }, - "ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true - } - } - }, "static-extend": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/static-extend/-/static-extend-0.1.2.tgz", @@ -25746,15 +25542,6 @@ "resolved": "https://registry.npmjs.org/stream-buffers/-/stream-buffers-2.2.0.tgz", "integrity": "sha1-kdX1Ew0c75bc+n9yaUUYh0HQnuQ=" }, - "stream-combiner": { - "version": "0.0.4", - "resolved": "https://registry.npmjs.org/stream-combiner/-/stream-combiner-0.0.4.tgz", - "integrity": "sha1-TV5DPBhSYd3mI8o/RMWGvPXErRQ=", - "dev": true, - "requires": { - "duplexer": "~0.1.1" - } - }, "stream-each": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/stream-each/-/stream-each-1.2.3.tgz", @@ -28667,36 +28454,6 @@ "xml-name-validator": "^3.0.0" } }, - "wait-on": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/wait-on/-/wait-on-5.3.0.tgz", - "integrity": "sha512-DwrHrnTK+/0QFaB9a8Ol5Lna3k7WvUR4jzSKmz0YaPBpuN2sACyiPVKVfj6ejnjcajAcvn3wlbTyMIn9AZouOg==", - "dev": true, - "requires": { - "axios": "^0.21.1", - "joi": "^17.3.0", - "lodash": "^4.17.21", - "minimist": "^1.2.5", - "rxjs": "^6.6.3" - }, - "dependencies": { - "axios": { - "version": "0.21.4", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz", - "integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==", - "dev": true, - "requires": { - "follow-redirects": "^1.14.0" - } - }, - "follow-redirects": { - "version": "1.14.4", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.4.tgz", - "integrity": "sha512-zwGkiSXC1MUJG/qmeIFH2HBJx9u0V46QGUe3YR1fXG8bXQxq7fLj0RjLZQ5nubr9qNJUZrH+xUcwXEoXNpfS+g==", - "dev": true - } - } - }, "walker": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/walker/-/walker-1.0.7.tgz", diff --git a/package.json b/package.json index 978460c80..e9438dd77 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,6 @@ "@babel/preset-env": "^7.14.7", "@commitlint/cli": "^11.0.0", "@commitlint/config-conventional": "^11.0.0", - "@cypress/webpack-preprocessor": "^5.9.1", "@vue/cli-plugin-babel": "^4.5.13", "@vue/cli-plugin-e2e-cypress": "^4.5.13", "@vue/cli-plugin-eslint": "^4.5.13", @@ -98,7 +97,6 @@ "sass-loader": "^10.2.0", "serve": "^11.3.2", "standard-version": "^9.3.0", - "start-server-and-test": "^1.12.5", "stylelint": "^13.13.1", "stylelint-config-standard": "^20.0.0", "svg-url-loader": "^7.1.1", diff --git a/tests/e2e/integration/networks.js b/tests/e2e/integration/networks.js index a36d2d644..b933ad4be 100644 --- a/tests/e2e/integration/networks.js +++ b/tests/e2e/integration/networks.js @@ -69,6 +69,8 @@ describe('Test cases for networks page', () => { .type(defaultNetwork.middlewareUrl) .get('[data-cy=connect]') .click() + .get('.modal .button-plain.close') + .click() .get('[data-cy=network-url]') .eq(-1) .should('contain', defaultNetwork.url) @@ -103,7 +105,7 @@ describe('Test cases for networks page', () => { .get('[data-cy=networks] .network-row') .should('have.length', 2) .get('[data-cy=networks] .network-row') - .eq(0) + .eq(1) .find('.checkmark') .should('have.class', 'checked'); }); diff --git a/tests/e2e/integration/other.js b/tests/e2e/integration/other.js index 5d7b2a60d..a465f6951 100644 --- a/tests/e2e/integration/other.js +++ b/tests/e2e/integration/other.js @@ -25,7 +25,7 @@ describe('Tests cases not connected to specific page', () => { ].forEach(({ path, redirect }) => { cy.login({}, path) .get('[data-cy=connect-node]') - .visit('extension/popup/popup') + .visit('') .urlEquals(redirect ? path : '/account'); }); }); diff --git a/tests/e2e/integration/withdraw.js b/tests/e2e/integration/withdraw.js index 4431bd8db..d32ae896b 100644 --- a/tests/e2e/integration/withdraw.js +++ b/tests/e2e/integration/withdraw.js @@ -13,7 +13,7 @@ describe('Test cases for Withdraw Page', () => { .should('be.visible') .get('.qr-code-reader video') .should('be.visible') - .get('.modal .close') + .get('.modal .button-plain.close') .click() .enterInputAmount('asd') diff --git a/tests/e2e/plugins/index.js b/tests/e2e/plugins/index.js index 7fd5adda4..8e22ce192 100644 --- a/tests/e2e/plugins/index.js +++ b/tests/e2e/plugins/index.js @@ -1,38 +1,8 @@ -const path = require('path'); -const wp = require('@cypress/webpack-preprocessor'); - -module.exports = (on, config) => { - const options = { - webpackOptions: { - resolve: { - extensions: ['.js'], - }, - module: { - rules: [ - { - test: /\.js?$/, - loader: 'babel-loader', - }, - ], - }, - }, - }; - on('file:preprocessor', wp(options)); - on('before:browser:launch', (browser, args) => { - if (browser.family === 'chromium' && browser.isHeaded) { - const extensionFolder = path.resolve(__dirname, '..', '..', '..', 'dist', 'extension'); - args.extensions.push(extensionFolder); - } - - return args; - }); - - return { - ...config, - fixturesFolder: 'tests/e2e/fixtures', - integrationFolder: 'tests/e2e/integration', - screenshotsFolder: 'tests/e2e/screenshots', - videosFolder: 'tests/e2e/videos', - supportFile: 'tests/e2e/support/index.js', - }; -}; +module.exports = (on, config) => ({ + ...config, + fixturesFolder: 'tests/e2e/fixtures', + integrationFolder: 'tests/e2e/integration', + screenshotsFolder: 'tests/e2e/screenshots', + videosFolder: 'tests/e2e/videos', + supportFile: 'tests/e2e/support/index.js', +}); diff --git a/tests/e2e/support/commands.js b/tests/e2e/support/commands.js index 00c9eb94a..45df0d060 100644 --- a/tests/e2e/support/commands.js +++ b/tests/e2e/support/commands.js @@ -3,14 +3,14 @@ import uuid from 'uuid'; import { formatDate, formatTime, getLoginState } from '../../../src/popup/utils'; Cypress.Commands.add('openPopup', (onBeforeLoad, route) => { - cy.visit(`extension/popup/popup${route ? `#${route}` : ''}`, { onBeforeLoad }); + cy.visit(`${route ? `#${route}` : ''}`, { onBeforeLoad }); }); Cypress.Commands.add('openAex2Popup', (type, txType) => { const id = uuid(); const params = `?id=${id}&type=${type}`; const onBeforeLoad = () => (txType ? browser.storage.local.set({ txType }) : browser.storage.local.remove('txType')); - cy.visit(`extension/popup/popup${params}`, { onBeforeLoad }) + cy.visit(`${params}`, { onBeforeLoad }) .get('[data-cy=popup-aex2]') .should('exist') .should('be.visible'); @@ -103,9 +103,7 @@ Cypress.Commands.add('logout', () => { }); Cypress.Commands.add('shouldRedirect', (url, to) => { - cy.visit(`extension/popup/popup#${url}`) - .url() - .should('eq', `${Cypress.config().popupUrl}/popup#${to}`); + cy.visit(`${url}`).urlEquals(to); }); Cypress.Commands.add('openPageMore', () => { @@ -166,14 +164,12 @@ Cypress.Commands.add('sendTip', (tip = {}) => { .click() .get('[data-cy=balance-info]') .should('be.visible') - .url() - .should('eq', `${Cypress.config().popupUrl}/popup#/account`) + .urlEquals('account') .get('[data-cy=pending-txs]') .should('be.visible') .get('[data-cy=success-tip]', { timeout: 240000 }) .should('be.visible') - .url() - .should('eq', `${Cypress.config().popupUrl}/popup#/success-tip`) + .urlEquals('success-tip') .get('[data-cy=tip-amount]') .should('contain', tip.amount) .get('[data-cy=tip-url]') @@ -213,7 +209,7 @@ Cypress.Commands.add( ); Cypress.Commands.add('urlEquals', (route) => { - cy.url().should('eq', `${Cypress.config().popupUrl}/popup#${route}`); + cy.url().should('contain', route); }); Cypress.Commands.add('openNetworks', () => { From 4d4d029429265d8cadb245f0705d3aee46c4c6bf Mon Sep 17 00:00:00 2001 From: Nikita Cedrik Date: Tue, 28 Sep 2021 19:28:27 +1000 Subject: [PATCH 14/65] test: add example unit test --- tests/unit/button.spec.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 tests/unit/button.spec.js diff --git a/tests/unit/button.spec.js b/tests/unit/button.spec.js new file mode 100644 index 000000000..0ecbce498 --- /dev/null +++ b/tests/unit/button.spec.js @@ -0,0 +1,12 @@ +import { shallowMount } from '@vue/test-utils'; +import Button from '../../src/popup/router/components/Button.vue'; + +describe('Button.vue', () => { + it('adds prop.fill class', () => { + const fill = 'primary'; + const wrapper = shallowMount(Button, { + propsData: { fill }, + }); + expect(wrapper.find(`.${fill}`).exists()).toBeTruthy(); + }); +}); From a8c3702f39978769c60bfb1ddbbbbb5e989a5726 Mon Sep 17 00:00:00 2001 From: Nikita Cedrik Date: Wed, 29 Sep 2021 16:04:32 +1000 Subject: [PATCH 15/65] feat(index): add message on disabled JavaScript --- public/index.html | 7 +++++++ src/popup/popup.js | 1 + src/styles/fullscreen-message.scss | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 src/styles/fullscreen-message.scss diff --git a/public/index.html b/public/index.html index ee2594077..4f0f3d3d0 100644 --- a/public/index.html +++ b/public/index.html @@ -16,6 +16,13 @@ + +
diff --git a/src/popup/popup.js b/src/popup/popup.js index d75feb281..b0df1aa18 100644 --- a/src/popup/popup.js +++ b/src/popup/popup.js @@ -3,6 +3,7 @@ import '../lib/initPolyfills'; import Vue from 'vue'; import sync from '../lib/vuexRouterSync'; import App from './App'; +import '../styles/fullscreen-message.scss'; import store from '../store'; import router from './router'; import { i18n } from '../store/plugins/languages'; diff --git a/src/styles/fullscreen-message.scss b/src/styles/fullscreen-message.scss new file mode 100644 index 000000000..613041fa7 --- /dev/null +++ b/src/styles/fullscreen-message.scss @@ -0,0 +1,18 @@ +@import 'typography'; + +body { + &, + > noscript { + > p.fullscreen-message { + margin: 0 auto; + padding-top: 30vh; + padding-left: 20px; + padding-right: 20px; + max-width: 400px; + text-align: center; + color: white; + + @extend %face-sans-20-regular; + } + } +} From daa8f70d3a7cb61d8ec54be7c2c70e2159fc9a25 Mon Sep 17 00:00:00 2001 From: Nikita Cedrik Date: Wed, 29 Sep 2021 16:10:21 +1000 Subject: [PATCH 16/65] feat(index): add message on exceptions while bundle initialising --- public/index.html | 14 +++++++++++++- src/styles/fullscreen-message.scss | 5 ++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/public/index.html b/public/index.html index 4f0f3d3d0..d746249eb 100644 --- a/public/index.html +++ b/public/index.html @@ -17,7 +17,7 @@