From 2149fe6a1aa1fdd0bc8de7bfdf6c2bbb45980bdb Mon Sep 17 00:00:00 2001 From: sproxet Date: Mon, 11 Oct 2021 16:39:00 +0700 Subject: [PATCH] Stop depending on blockchain events from firod. --- src/daemon/firod.ts | 1 + src/daemon/modules/block.ts | 5 ----- src/daemon/modules/blockchain.ts | 9 --------- src/renderer/components/CoinSwapPage/CoinSwapDetail.vue | 2 +- src/renderer/components/SendPage.vue | 2 +- src/renderer/components/Sidebar/BlockchainStatus.vue | 6 +++--- src/renderer/components/TransactionsPage.vue | 2 +- src/store/modules/ApiStatus.ts | 5 ++++- src/store/modules/App.js | 2 +- src/store/modules/Blockchain.js | 7 ------- src/store/modules/Znode.ts | 2 +- 11 files changed, 13 insertions(+), 30 deletions(-) delete mode 100644 src/daemon/modules/block.ts delete mode 100644 src/daemon/modules/blockchain.ts diff --git a/src/daemon/firod.ts b/src/daemon/firod.ts index 64b892ac..3f44aa1e 100644 --- a/src/daemon/firod.ts +++ b/src/daemon/firod.ts @@ -188,6 +188,7 @@ export interface ApiStatusData { hasMnemonic: boolean; smartFeePerKb: number; hasSentInitialStateWallet: boolean; + latestBlockTimestamp: number; } export interface ApiStatus { diff --git a/src/daemon/modules/block.ts b/src/daemon/modules/block.ts deleted file mode 100644 index ae067653..00000000 --- a/src/daemon/modules/block.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { Firod } from '../firod'; - -export async function handleEvent(store: any, firod: Firod, data: any) { - store.commit('Blockchain/updateBlockchain', data); -} \ No newline at end of file diff --git a/src/daemon/modules/blockchain.ts b/src/daemon/modules/blockchain.ts deleted file mode 100644 index 859fb98f..00000000 --- a/src/daemon/modules/blockchain.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Firod } from '../firod'; - -export async function handleEvent(store: any, firod: Firod, data: any) { - store.commit('Blockchain/updateBlockchain', data); -} - -export async function initialize(store: any, firod: Firod) { - store.commit('Blockchain/updateBlockchain', await firod.send(null, 'get', 'blockchain', null)); -} diff --git a/src/renderer/components/CoinSwapPage/CoinSwapDetail.vue b/src/renderer/components/CoinSwapPage/CoinSwapDetail.vue index 4aaca9f7..eaaba42d 100644 --- a/src/renderer/components/CoinSwapPage/CoinSwapDetail.vue +++ b/src/renderer/components/CoinSwapPage/CoinSwapDetail.vue @@ -458,7 +458,7 @@ export default { availablePrivate: 'Balance/availablePrivate', availablePublic: 'Balance/availablePublic', maxPrivateSend: 'Balance/maxPrivateSend', - isBlockchainSynced: 'Blockchain/isBlockchainSynced', + isBlockchainSynced: 'ApiStatus/isBlockchainSynced', isLelantusAllowed: 'ApiStatus/isLelantusAllowed', isBigWallet: 'Transactions/isBigWallet', smartFeePerKb: 'ApiStatus/smartFeePerKb' diff --git a/src/renderer/components/SendPage.vue b/src/renderer/components/SendPage.vue index b0fbd6a9..6eca447b 100644 --- a/src/renderer/components/SendPage.vue +++ b/src/renderer/components/SendPage.vue @@ -228,7 +228,7 @@ export default { ...mapGetters({ network: 'ApiStatus/network', isLelantusAllowed: 'ApiStatus/isLelantusAllowed', - isBlockchainSynced: 'Blockchain/isBlockchainSynced', + isBlockchainSynced: 'ApiStatus/isBlockchainSynced', availablePrivate: 'Balance/availablePrivate', availablePublic: 'Balance/availablePublic', sendAddresses: 'AddressBook/sendAddresses', diff --git a/src/renderer/components/Sidebar/BlockchainStatus.vue b/src/renderer/components/Sidebar/BlockchainStatus.vue index bfe15123..669f3794 100644 --- a/src/renderer/components/Sidebar/BlockchainStatus.vue +++ b/src/renderer/components/Sidebar/BlockchainStatus.vue @@ -37,10 +37,10 @@ export default { computed: { ...mapGetters({ network: 'ApiStatus/network', - connections: 'Blockchain/connections', + connections: 'ApiStatus/connections', currentBlockHeight: 'ApiStatus/currentBlockHeight', - estimatedBlockHeight: 'Blockchain/estimatedBlockHeight', - isBlockchainSynced: 'Blockchain/isBlockchainSynced', + estimatedBlockHeight: 'ApiStatus/estimatedBlockHeight', + isBlockchainSynced: 'ApiStatus/isBlockchainSynced', }) } } diff --git a/src/renderer/components/TransactionsPage.vue b/src/renderer/components/TransactionsPage.vue index 6b4ac651..5f7b7dec 100644 --- a/src/renderer/components/TransactionsPage.vue +++ b/src/renderer/components/TransactionsPage.vue @@ -97,7 +97,7 @@ export default { ...mapGetters({ userVisibleTransactions: 'Transactions/userVisibleTransactions', addressBook: 'AddressBook/addressBook', - isBlockchainSynced: 'Blockchain/isBlockchainSynced', + isBlockchainSynced: 'ApiStatus/isBlockchainSynced', isReindexing: 'ApiStatus/isReindexing' }), diff --git a/src/store/modules/ApiStatus.ts b/src/store/modules/ApiStatus.ts index aaa50c38..2060ae06 100644 --- a/src/store/modules/ApiStatus.ts +++ b/src/store/modules/ApiStatus.ts @@ -43,7 +43,10 @@ const getters = { // We will return 0 if apiStatus hasn't yet loaded. enabledZnodeCount: (state, getters): number => (getters.apiStatusData.Znode || {}).enabledCount || 0, // This is the recommended fee per kb, or 1000 if it is undefined or lower than that. - smartFeePerKb: (state, getters): number => Math.max(1000, getters.apiStatusData.smartFeePerKb || 1000) + smartFeePerKb: (state, getters): number => Math.max(1000, getters.apiStatusData.smartFeePerKb || 1000), + estimatedBlockHeight: (state, getters): number => Math.floor((Date.now() / 1000 - getters.lastestBlockTimestamp) / 300) + getters.currentBlockHeight, + isBlockchainSynced: (state, getters): boolean => getters.apiStatusData.synced, + connections: (state, getters): number => getters.apiStatusData.connections }; export default { diff --git a/src/store/modules/App.js b/src/store/modules/App.js index 5b41d4c6..ec891f4f 100644 --- a/src/store/modules/App.js +++ b/src/store/modules/App.js @@ -174,7 +174,7 @@ const getters = { isInitialized: (state) => state.isInitialized, firodHasStarted: (state) => state.firodHasStarted, showPaymentPendingWarning: (state, getters, rootState, rootGetters) => - rootGetters['Blockchain/isBlockchainSynced'] && rootGetters['Balance/availablePublic'] > 0.01e8, + rootGetters['ApiStatus/isBlockchainSynced'] && rootGetters['Balance/availablePublic'] > 0.01e8, // If waitingReason is not undefined, WaitingScreen (shown by MainLayout) will display that reason to the user as an // overlay. waitingReason: (state) => state.waitingReason, diff --git a/src/store/modules/Blockchain.js b/src/store/modules/Blockchain.js index f0d28b3f..8937566f 100644 --- a/src/store/modules/Blockchain.js +++ b/src/store/modules/Blockchain.js @@ -67,13 +67,6 @@ export const getters = { connections: (state) => state.connections, hasConnections: (state) => !!state.connections, estimatedTimeUntilSynced: (state) => state.estimatedTimeUntilSynced, - estimatedBlockHeight: (state, getters) => { - const now = Date.now() - const remainingTime = now - (getters.currentBlockTimestamp * 1000) - const remainingBlocks = remainingTime / getters.averageBlockTimeInMilliSeconds - - return Math.floor(getters.currentBlockHeight + remainingBlocks) - } } diff --git a/src/store/modules/Znode.ts b/src/store/modules/Znode.ts index 8f706a6b..4dd7dc3f 100644 --- a/src/store/modules/Znode.ts +++ b/src/store/modules/Znode.ts @@ -60,7 +60,7 @@ const getters = { // in milliseconds paymentPeriod: (state, getters, rootState, rootGetters): number => { const enabledZnodeCount = rootGetters['ApiStatus/enabledZnodeCount']; - const blockTime = rootGetters['Blockchain/averageBlockTimeInMilliSeconds']; + const blockTime = 300e3; return blockTime * enabledZnodeCount; } };