From 3070305eede5d11bcf2ca2ec86dbec2dc56dd477 Mon Sep 17 00:00:00 2001 From: Philipp Walter Date: Wed, 6 Dec 2023 14:56:27 +0100 Subject: [PATCH] refactor: use typed store.dispatch --- __tests__/backups.ts | 3 +-- src/store/actions/activity.ts | 4 +--- src/store/actions/backup.ts | 4 +--- src/store/actions/blocktank.ts | 4 +--- src/store/actions/checks.ts | 4 +--- src/store/actions/fees.ts | 4 +--- src/store/actions/lightning.ts | 4 +--- src/store/actions/metadata.ts | 4 +--- src/store/actions/receive.ts | 4 +--- src/store/actions/settings.ts | 6 ++---- src/store/actions/slashtags.ts | 4 +--- src/store/actions/todos.ts | 4 +--- src/store/actions/ui.ts | 4 +--- src/store/actions/user.ts | 4 +--- src/store/actions/wallet.ts | 4 +--- src/store/actions/widgets.ts | 4 +--- src/store/helpers.ts | 5 ++--- 17 files changed, 19 insertions(+), 51 deletions(-) diff --git a/__tests__/backups.ts b/__tests__/backups.ts index f1d142d6e..b8831eef2 100644 --- a/__tests__/backups.ts +++ b/__tests__/backups.ts @@ -26,9 +26,9 @@ import { performWidgetsRestore, } from '../src/store/actions/backup'; import { + dispatch, getActivityStore, getBlocktankStore, - getDispatch, getMetaDataStore, getSettingsStore, getWidgetsStore, @@ -274,7 +274,6 @@ describe('Remote backups', () => { }); it('Backups and restores Blocktank orders', async () => { - const dispatch = getDispatch(); addPaidBlocktankOrder({ orderId: 'id', txid: 'txid' }); dispatch({ type: actions.UPDATE_BLOCKTANK_ORDER, diff --git a/src/store/actions/activity.ts b/src/store/actions/activity.ts index 740f1a034..e1d05237e 100644 --- a/src/store/actions/activity.ts +++ b/src/store/actions/activity.ts @@ -6,7 +6,7 @@ import { IActivityItem, TLightningActivityItem, } from '../types/activity'; -import { getBlocktankStore, getDispatch } from '../helpers'; +import { getBlocktankStore, dispatch } from '../helpers'; import { onChainTransactionToActivityItem } from '../../utils/activity'; import { getCurrentWallet } from '../../utils/wallet'; import { formatBoostedActivityItems } from '../../utils/boost'; @@ -17,8 +17,6 @@ import { checkPendingCJitEntries } from './blocktank'; import { getLightningChannels } from '../../utils/lightning'; import { updateSettings } from './settings'; -const dispatch = getDispatch(); - /** * Adds the provided activity item to the activity list. * @param {IActivityItem} activityItem diff --git a/src/store/actions/backup.ts b/src/store/actions/backup.ts index f8c7cf3d3..33bf6b408 100644 --- a/src/store/actions/backup.ts +++ b/src/store/actions/backup.ts @@ -2,7 +2,7 @@ import { err, ok, Result } from '@synonymdev/result'; import lm, { ldk, ENetworks, TLdkData } from '@synonymdev/react-native-ldk'; import actions from './actions'; -import { getBackupStore, getDispatch } from '../helpers'; +import { getBackupStore, dispatch } from '../helpers'; import { EBackupCategories, fetchBackup, @@ -47,8 +47,6 @@ import { __BACKUPS_SERVER_PUBKEY__, } from '../../constants/env'; -const dispatch = getDispatch(); - /** * Triggers a full remote backup * @return {Promise>} diff --git a/src/store/actions/blocktank.ts b/src/store/actions/blocktank.ts index 8e681d32f..608acdc0b 100644 --- a/src/store/actions/blocktank.ts +++ b/src/store/actions/blocktank.ts @@ -3,7 +3,7 @@ import { err, ok, Result } from '@synonymdev/result'; import actions from './actions'; import { resetSendTransaction, updateSendTransaction } from './wallet'; import { setLightningSettingUpStep } from './user'; -import { getBlocktankStore, getDispatch, getWalletStore } from '../helpers'; +import { getBlocktankStore, getWalletStore, dispatch } from '../helpers'; import * as blocktank from '../../utils/blocktank'; import { createOrder, @@ -42,8 +42,6 @@ import { } from '@synonymdev/blocktank-lsp-http-client'; import { CJitStateEnum } from '@synonymdev/blocktank-lsp-http-client/dist/shared/CJitStateEnum'; -const dispatch = getDispatch(); - /** * Retrieves & updates the status of stored orders that may have changed. * @returns {Promise>} diff --git a/src/store/actions/checks.ts b/src/store/actions/checks.ts index 5cb12c27a..3a4443962 100644 --- a/src/store/actions/checks.ts +++ b/src/store/actions/checks.ts @@ -1,13 +1,11 @@ import actions from './actions'; -import { getDispatch } from '../helpers'; +import { dispatch } from '../helpers'; import { TWalletName } from '../types/wallet'; import { getSelectedNetwork, getSelectedWallet } from '../../utils/wallet'; import { TAvailableNetworks } from '../../utils/networks'; import { TStorageWarning } from '../types/checks'; import { getWarnings } from '../../utils/checks'; -const dispatch = getDispatch(); - /** * Adds a single warning. * @param {TStorageWarning} warning diff --git a/src/store/actions/fees.ts b/src/store/actions/fees.ts index fe69d6917..6af9765cb 100644 --- a/src/store/actions/fees.ts +++ b/src/store/actions/fees.ts @@ -1,13 +1,11 @@ import { ok, err, Result } from '@synonymdev/result'; import actions from './actions'; -import { getDispatch, getFeesStore } from '../helpers'; +import { dispatch, getFeesStore } from '../helpers'; import { getFeeEstimates } from '../../utils/wallet/transactions'; import { TAvailableNetworks } from '../../utils/networks'; import { IOnchainFees } from '../types/fees'; -const dispatch = getDispatch(); - export const REFRESH_INTERVAL = 60 * 30; // in seconds, 30 minutes export const updateOnchainFeeEstimates = async ({ diff --git a/src/store/actions/lightning.ts b/src/store/actions/lightning.ts index dd44d0af0..28225771e 100644 --- a/src/store/actions/lightning.ts +++ b/src/store/actions/lightning.ts @@ -4,7 +4,7 @@ import { TChannel, TInvoice } from '@synonymdev/react-native-ldk'; import { getLNURLParams, lnurlChannel } from '@synonymdev/react-native-lnurl'; import actions from './actions'; -import { getDispatch, getLightningStore, getMetaDataStore } from '../helpers'; +import { dispatch, getLightningStore, getMetaDataStore } from '../helpers'; import { TAvailableNetworks } from '../../utils/networks'; import { getActivityItemById } from '../../utils/activity'; import { getSelectedNetwork, getSelectedWallet } from '../../utils/wallet'; @@ -29,8 +29,6 @@ import { import { EPaymentType, TWalletName } from '../types/wallet'; import { EActivityType, TLightningActivityItem } from '../types/activity'; -const dispatch = getDispatch(); - /** * Attempts to update the node id for the given wallet and network. * @param {string} nodeId diff --git a/src/store/actions/metadata.ts b/src/store/actions/metadata.ts index b5766144c..5e5dcf67c 100644 --- a/src/store/actions/metadata.ts +++ b/src/store/actions/metadata.ts @@ -1,12 +1,10 @@ import { ok, Result } from '@synonymdev/result'; import actions from './actions'; -import { getDispatch, getMetaDataStore } from '../helpers'; +import { dispatch, getMetaDataStore } from '../helpers'; import { getCurrentWallet } from '../../utils/wallet'; import { EPaymentType } from '../types/wallet'; import { IMetadata } from '../types/metadata'; -const dispatch = getDispatch(); - /* * This action updates transactions tags */ diff --git a/src/store/actions/receive.ts b/src/store/actions/receive.ts index 2858e6b3b..f9b10ebf5 100644 --- a/src/store/actions/receive.ts +++ b/src/store/actions/receive.ts @@ -1,9 +1,7 @@ import { ok, Result } from '@synonymdev/result'; import { ICJitEntry } from '@synonymdev/blocktank-lsp-http-client'; import actions from './actions'; -import { getDispatch } from '../helpers'; - -const dispatch = getDispatch(); +import { dispatch } from '../helpers'; export const updateInvoice = (payload: { amount?: number; diff --git a/src/store/actions/settings.ts b/src/store/actions/settings.ts index 7fd02064f..d09c96414 100644 --- a/src/store/actions/settings.ts +++ b/src/store/actions/settings.ts @@ -2,7 +2,7 @@ import { err, ok, Result } from '@synonymdev/result'; import RNRestart from 'react-native-restart'; import actions from './actions'; -import { getDispatch } from '../helpers'; +import { dispatch } from '../helpers'; import i18n from '../../utils/i18n'; import { sleep } from '../../utils/helpers'; import { removePin } from '../../utils/settings'; @@ -14,8 +14,6 @@ import { getAllKeychainKeys, resetKeychainValue } from '../../utils/keychain'; import { ICustomElectrumPeer, ISettings, TChest } from '../types/settings'; import { TWalletName } from '../types/wallet'; -const dispatch = getDispatch(); - export const updateSettings = (payload: Partial): Result => { dispatch({ type: actions.UPDATE_SETTINGS, @@ -84,7 +82,7 @@ export const wipeApp = async ({ showToast({ type: 'success', title: i18n.t('security:wiped_title'), - description: i18n.t('security:wiped_description'), + description: i18n.t('security:wiped_message'), }); } diff --git a/src/store/actions/slashtags.ts b/src/store/actions/slashtags.ts index ff2283efc..6692f09e9 100644 --- a/src/store/actions/slashtags.ts +++ b/src/store/actions/slashtags.ts @@ -5,12 +5,10 @@ import b4a from 'b4a'; import { __SLASHTAGS_SEEDER_BASE_URL__ } from '../../constants/env'; import actions from './actions'; -import { getDispatch, getSlashtagsStore } from '../helpers'; +import { dispatch, getSlashtagsStore } from '../helpers'; import { BasicProfile, ISlashtags, Link, LocalLink } from '../types/slashtags'; import { seedDrives } from '../../utils/slashtags'; -const dispatch = getDispatch(); - /** * Sets the onboarding profile state. */ diff --git a/src/store/actions/todos.ts b/src/store/actions/todos.ts index 9f5251a4d..c8a56b3b8 100644 --- a/src/store/actions/todos.ts +++ b/src/store/actions/todos.ts @@ -2,11 +2,9 @@ import { ok, Result } from '@synonymdev/result'; import { TChannel } from '@synonymdev/react-native-ldk'; import actions from './actions'; -import { getDispatch } from '../helpers'; +import { dispatch } from '../helpers'; import { TTodoType } from '../types/todos'; -const dispatch = getDispatch(); - export const hideTodo = (id: TTodoType): Result => { dispatch({ type: actions.HIDE_TODO, diff --git a/src/store/actions/ui.ts b/src/store/actions/ui.ts index 94531cc69..3ded79033 100644 --- a/src/store/actions/ui.ts +++ b/src/store/actions/ui.ts @@ -8,14 +8,12 @@ import { TProfileLink, ViewControllerParamList, } from '../types/ui'; -import { getActivityStore, getDispatch } from '../helpers'; +import { getActivityStore, dispatch } from '../helpers'; import actions from './actions'; const releaseUrl = 'https://github.com/synonymdev/bitkit/releases/download/updater/release.json'; -const dispatch = getDispatch(); - export const updateUi = (payload: Partial): Result => { dispatch({ type: actions.UPDATE_UI, diff --git a/src/store/actions/user.ts b/src/store/actions/user.ts index 69b8e0b33..5ea0879df 100644 --- a/src/store/actions/user.ts +++ b/src/store/actions/user.ts @@ -1,12 +1,10 @@ import { ok, Result } from '@synonymdev/result'; import actions from './actions'; -import { getDispatch } from '../helpers'; +import { dispatch } from '../helpers'; import { isGeoBlocked } from '../../utils/blocktank'; import { IUser } from '../types/user'; -const dispatch = getDispatch(); - export const updateUser = (payload: Partial): Result => { dispatch({ type: actions.UPDATE_USER, diff --git a/src/store/actions/wallet.ts b/src/store/actions/wallet.ts index 833f2e9dc..b6121aac1 100644 --- a/src/store/actions/wallet.ts +++ b/src/store/actions/wallet.ts @@ -40,8 +40,8 @@ import { rescanAddresses, } from '../../utils/wallet'; import { + dispatch, getBlocktankStore, - getDispatch, getFeesStore, getSettingsStore, getWalletStore, @@ -87,8 +87,6 @@ import { getFakeTransaction } from '../../utils/wallet/testing'; import { EActivityType, TOnchainActivityItem } from '../types/activity'; import i18n from '../../utils/i18n'; -const dispatch = getDispatch(); - export const updateWallet = ( payload: Partial, ): Result => { diff --git a/src/store/actions/widgets.ts b/src/store/actions/widgets.ts index f0c8f8072..9aed4c246 100644 --- a/src/store/actions/widgets.ts +++ b/src/store/actions/widgets.ts @@ -1,5 +1,5 @@ import actions from './actions'; -import { getDispatch } from '../helpers'; +import { dispatch } from '../helpers'; import { IWidgetsStore, SlashFeedJSON, @@ -7,8 +7,6 @@ import { } from '../types/widgets'; import { ok, Result } from '@synonymdev/result'; -const dispatch = getDispatch(); - export const updateWidgets = ( payload: Partial, ): Result => { diff --git a/src/store/helpers.ts b/src/store/helpers.ts index 94b3d5b50..04f8fa22d 100644 --- a/src/store/helpers.ts +++ b/src/store/helpers.ts @@ -1,4 +1,3 @@ -import { Dispatch } from 'redux'; import cloneDeep from 'lodash/cloneDeep'; import store from '../store'; @@ -81,6 +80,6 @@ export const getBackupStore = (): IBackup => { }; /* -Used to get dispatch outside of a component. +Used to dispatch outside of a component. */ -export const getDispatch = (): Dispatch => store.dispatch; +export const { dispatch } = store;