From 275c29049e1a13982e643f201f45ca4e102ab3e0 Mon Sep 17 00:00:00 2001 From: Ysrbolles Date: Thu, 19 Sep 2024 22:18:21 +0100 Subject: [PATCH 1/4] Refactor code to fetch imported multisig transactions --- src/App.vue | 1 + src/components/CamBadge.vue | 6 +++ src/components/wallet/manage/MyKeys.vue | 25 ++++++++- src/store/modules/signavault/signavault.ts | 63 ++++++++++++++++++++++ src/store/modules/signavault/types.ts | 1 + 5 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 src/components/CamBadge.vue diff --git a/src/App.vue b/src/App.vue index 87f4c8d7c..df2faad92 100644 --- a/src/App.vue +++ b/src/App.vue @@ -49,6 +49,7 @@ export default { mounted() { let { updateSuiteStore } = this.globalHelper() updateSuiteStore(this.$store.state) + this.$store.dispatch('Signavault/getImportedMultiSigTransaction') }, watch: { '$store.state.isAuth': [ diff --git a/src/components/CamBadge.vue b/src/components/CamBadge.vue new file mode 100644 index 000000000..ae5a73dba --- /dev/null +++ b/src/components/CamBadge.vue @@ -0,0 +1,6 @@ + + diff --git a/src/components/wallet/manage/MyKeys.vue b/src/components/wallet/manage/MyKeys.vue index 5bc39f3ee..6ddf45cfe 100644 --- a/src/components/wallet/manage/MyKeys.vue +++ b/src/components/wallet/manage/MyKeys.vue @@ -73,8 +73,12 @@ export default class MyKeys extends Vue { return this.$store.getters['Accounts/account'] } + get getPendingTransaction() { + return this.$store.getters['Signavault/importedTransactions'] + } + get inactiveWallets(): WalletType[] { - return this.wallets.filter((wallet) => wallet !== this.activeWallet) + return this.checkInactivePendingWallet() } get wallets(): WalletType[] { @@ -182,6 +186,25 @@ export default class MyKeys extends Vue { } }, 200) } + + checkInactivePendingWallet() { + const pendingTxs = this.getPendingTransaction + const wallets = this.wallets.filter((wallet) => wallet !== this.activeWallet) + + wallets.forEach((wallet) => { + if (wallet.type === 'multisig') { + const matchingTx = pendingTxs.find( + (tx) => tx.tx.alias === wallet.getStaticAddress('P') + ) + + if (matchingTx) { + Object.assign(wallet, { pendingTx: matchingTx }) + } + } + }) + + return wallets + } } diff --git a/src/store/modules/signavault/signavault.ts b/src/store/modules/signavault/signavault.ts index 62e1eed35..f9d7210a9 100644 --- a/src/store/modules/signavault/signavault.ts +++ b/src/store/modules/signavault/signavault.ts @@ -8,6 +8,7 @@ const signavault_module: Module = { namespaced: true, state: { transactions: [], + importedTransactions: [], }, getters: { transactions(state) { @@ -16,6 +17,10 @@ const signavault_module: Module = { transaction: (state) => (txID: string) => { return state.transactions.find((t) => t.tx.id === txID) }, + + importedTransactions(state) { + return state.importedTransactions + }, }, mutations: { clear(state) { @@ -24,6 +29,13 @@ const signavault_module: Module = { setTx(state, newTx: MultisigTx[]) { state.transactions = newTx }, + + setImportedTx(state, newTx: MultisigTx[]) { + state.importedTransactions = newTx + }, + clearImported(state) { + state.importedTransactions = [] + }, }, actions: { async updateTransaction({ commit, rootState, rootGetters }) { @@ -58,6 +70,57 @@ const signavault_module: Module = { return commit('clear') } }, + + async getImportedMultiSigTransaction({ commit, rootState, rootGetters }) { + try { + const network = rootGetters['Network/selectedNetwork'] + if (!network) { + commit('clearImported') + return + } + + const multisigWallets = rootState.wallets.filter( + (wallet) => wallet.type === 'multisig' + ) + + const allTxPromises = multisigWallets.map(async (wallet) => { + if (!(wallet instanceof MultisigWallet)) { + commit('clearImported') + return + } + + const staticAddress = wallet.getStaticAddress('P') + const signingKeyPair = wallet.wallets[0]?.getStaticKeyPair() + + if (!signingKeyPair) { + console.log('wallet returned undefined staticKeyPair') + commit('clearImported') + return + } + + return await SignaVaultTx(staticAddress, signingKeyPair) // Get transactions for each wallet + }) + + const allTxResults = (await Promise.all(allTxPromises)).flat() + + const multisigTxs = allTxResults + .map((mms, index) => { + const wallet = multisigWallets[index] + if (!mms || !(wallet instanceof MultisigWallet)) return [] + + return { + tx: mms, + state: wallet.getSignatureStatus(mms), + } + }) + .filter((tx: any) => tx.length !== 0) // Filter out empty results + + commit('setImportedTx', multisigTxs.flat()) + } catch (e: any) { + console.error('Error fetching transactions:', e) + commit('clearImported') + } + }, }, } diff --git a/src/store/modules/signavault/types.ts b/src/store/modules/signavault/types.ts index 28a214505..6c1fc74cb 100644 --- a/src/store/modules/signavault/types.ts +++ b/src/store/modules/signavault/types.ts @@ -2,6 +2,7 @@ import { ModelMultisigTx } from '@/signavault_api' export interface SignavaultState { transactions: MultisigTx[] + importedTransactions: MultisigTx[] } export interface MultisigTx { From 6ab5c82f0d0bc5b83542c17c9940b0c91bb6f7b6 Mon Sep 17 00:00:00 2001 From: Ysrbolles Date: Sun, 22 Sep 2024 22:25:10 +0100 Subject: [PATCH 2/4] Refactor CamBadge component and add pending transaction badge to KeyRow component --- src/components/CamBadge.vue | 111 +++++++++++++++++++++++- src/components/wallet/manage/KeyRow.vue | 23 ++++- src/components/wallet/manage/MyKeys.vue | 32 ++++--- src/js/wallets/WalletCore.ts | 1 + 4 files changed, 150 insertions(+), 17 deletions(-) diff --git a/src/components/CamBadge.vue b/src/components/CamBadge.vue index ae5a73dba..63afcbcd8 100644 --- a/src/components/CamBadge.vue +++ b/src/components/CamBadge.vue @@ -1,6 +1,113 @@ + + + diff --git a/src/components/wallet/manage/KeyRow.vue b/src/components/wallet/manage/KeyRow.vue index 6c8b5c451..be36763da 100644 --- a/src/components/wallet/manage/KeyRow.vue +++ b/src/components/wallet/manage/KeyRow.vue @@ -93,6 +93,11 @@ > {{ $t('keys.view_priv_key') }} +