From 91d18c4253a192903dd76f1d8688014a8dc0f946 Mon Sep 17 00:00:00 2001 From: tuliomir Date: Tue, 16 Apr 2024 13:19:17 -0300 Subject: [PATCH] refactor: services to modules folder --- src/App.js | 2 +- src/components/ModalAddManyTokens.js | 2 +- src/components/ModalAddToken.js | 2 +- src/components/ModalBackupWords.js | 2 +- src/components/ModalPin.js | 2 +- src/components/ModalResetAllData.js | 2 +- src/components/ModalSendTx.js | 2 +- src/components/ModalUnregisteredTokenInfo.js | 2 +- src/components/TokenHistory.js | 2 +- src/components/TxData.js | 2 +- src/components/WalletAddress.js | 2 +- src/components/atomic-swap/ModalAtomicReceive.js | 2 +- src/components/tokens/TokenDelegate.js | 2 +- src/components/tokens/TokenDestroy.js | 2 +- src/components/tokens/TokenMelt.js | 2 +- src/components/tokens/TokenMint.js | 2 +- .../wallet.singleton.js => modules/wallet.js} | 14 ++++++++++---- src/sagas/atomicSwap.js | 2 +- src/sagas/tokens.js | 2 +- src/sagas/wallet.js | 2 +- src/screens/AddressList.js | 2 +- src/screens/ChoosePassphrase.js | 2 +- src/screens/CreateNFT.js | 2 +- src/screens/CreateToken.js | 2 +- src/screens/SendTokens.js | 2 +- src/screens/Server.js | 2 +- src/screens/TransactionDetail.js | 2 +- src/screens/Wallet.js | 2 +- src/screens/atomic-swap/EditSwap.js | 2 +- src/screens/atomic-swap/NewSwap.js | 2 +- src/utils/tokens.js | 2 +- 31 files changed, 40 insertions(+), 34 deletions(-) rename src/{services/wallet.singleton.js => modules/wallet.js} (69%) diff --git a/src/App.js b/src/App.js index 79efd270..523db515 100644 --- a/src/App.js +++ b/src/App.js @@ -51,7 +51,7 @@ import EditSwap from './screens/atomic-swap/EditSwap'; import NewSwap from './screens/atomic-swap/NewSwap'; import ImportExisting from './screens/atomic-swap/ImportExisting'; import LOCAL_STORE from './storage'; -import { getGlobalWallet } from "./services/wallet.singleton"; +import { getGlobalWallet } from "./modules/wallet.singleton"; function Root() { const { diff --git a/src/components/ModalAddManyTokens.js b/src/components/ModalAddManyTokens.js index 315367cd..4b995e76 100644 --- a/src/components/ModalAddManyTokens.js +++ b/src/components/ModalAddManyTokens.js @@ -12,7 +12,7 @@ import $ from 'jquery'; import hathorLib from '@hathor/wallet-lib'; import tokens from '../utils/tokens'; import walletUtils from "../utils/wallet"; -import { getGlobalWallet } from "../services/wallet.singleton"; +import { getGlobalWallet } from "../modules/wallet.singleton"; /** * Component that shows a modal to add many unknown tokens to the wallet (bulk import) diff --git a/src/components/ModalAddToken.js b/src/components/ModalAddToken.js index 122f42a4..e4c09121 100644 --- a/src/components/ModalAddToken.js +++ b/src/components/ModalAddToken.js @@ -11,7 +11,7 @@ import $ from 'jquery'; import tokens from '../utils/tokens'; import hathorLib from '@hathor/wallet-lib'; import walletUtils from "../utils/wallet"; -import { getGlobalWallet } from "../services/wallet.singleton"; +import { getGlobalWallet } from "../modules/wallet.singleton"; /** * Component that shows a modal to add one specific unknown token to the wallet diff --git a/src/components/ModalBackupWords.js b/src/components/ModalBackupWords.js index 064ceea1..7dafbb43 100644 --- a/src/components/ModalBackupWords.js +++ b/src/components/ModalBackupWords.js @@ -14,7 +14,7 @@ import { updateWords } from '../actions/index'; import { connect } from 'react-redux'; import hathorLib from '@hathor/wallet-lib'; import { WORDS_VALIDATION } from '../constants'; -import { getGlobalWallet } from "../services/wallet.singleton"; +import { getGlobalWallet } from "../modules/wallet.singleton"; const mapDispatchToProps = dispatch => { diff --git a/src/components/ModalPin.js b/src/components/ModalPin.js index 8d4d7c07..0b728fdc 100644 --- a/src/components/ModalPin.js +++ b/src/components/ModalPin.js @@ -10,7 +10,7 @@ import { t } from 'ttag'; import $ from 'jquery'; import PinInput from './PinInput'; import PropTypes from "prop-types"; -import { getGlobalWallet } from "../services/wallet.singleton"; +import { getGlobalWallet } from "../modules/wallet.singleton"; /** * Component that shows a modal with a form to ask for the user PIN diff --git a/src/components/ModalResetAllData.js b/src/components/ModalResetAllData.js index 32fe87a2..3ad4064e 100644 --- a/src/components/ModalResetAllData.js +++ b/src/components/ModalResetAllData.js @@ -11,7 +11,7 @@ import $ from 'jquery'; import { CONFIRM_RESET_MESSAGE } from '../constants'; import SpanFmt from './SpanFmt'; import LOCAL_STORE from '../storage'; -import { getGlobalWallet } from "../services/wallet.singleton"; +import { getGlobalWallet } from "../modules/wallet.singleton"; /** * Component that shows a modal to ask form confirmation data to reset the wallet diff --git a/src/components/ModalSendTx.js b/src/components/ModalSendTx.js index 1ddc67ec..847b8f19 100644 --- a/src/components/ModalSendTx.js +++ b/src/components/ModalSendTx.js @@ -13,7 +13,7 @@ import PropTypes from "prop-types"; import SendTxHandler from '../components/SendTxHandler'; import ReactLoading from 'react-loading'; import { colors } from '../constants'; -import { getGlobalWallet } from "../services/wallet.singleton"; +import { getGlobalWallet } from "../modules/wallet.singleton"; const mapStateToProps = (state) => { diff --git a/src/components/ModalUnregisteredTokenInfo.js b/src/components/ModalUnregisteredTokenInfo.js index a5fc78f0..a7d6b81e 100644 --- a/src/components/ModalUnregisteredTokenInfo.js +++ b/src/components/ModalUnregisteredTokenInfo.js @@ -13,7 +13,7 @@ import SpanFmt from './SpanFmt'; import TokenGeneralInfo from '../components/TokenGeneralInfo'; import hathorLib from '@hathor/wallet-lib'; import PropTypes from 'prop-types'; -import { getGlobalWallet } from "../services/wallet.singleton"; +import { getGlobalWallet } from "../modules/wallet.singleton"; /** * Component that shows a modal with information about an unregistered token diff --git a/src/components/TokenHistory.js b/src/components/TokenHistory.js index 6a2a133e..2069efca 100644 --- a/src/components/TokenHistory.js +++ b/src/components/TokenHistory.js @@ -19,7 +19,7 @@ import { colors } from '../constants'; import TokenPagination from './TokenPagination'; import HathorAlert from './HathorAlert'; import { TOKEN_DOWNLOAD_STATUS } from '../sagas/tokens'; -import { getGlobalWallet } from "../services/wallet.singleton"; +import { getGlobalWallet } from "../modules/wallet.singleton"; const mapStateToProps = (state, props) => { const defaultTokenHistory = { diff --git a/src/components/TxData.js b/src/components/TxData.js index 6d7b3d62..985272b2 100644 --- a/src/components/TxData.js +++ b/src/components/TxData.js @@ -22,7 +22,7 @@ import { MAX_GRAPH_LEVEL } from '../constants'; import helpers from '../utils/helpers'; import { GlobalModalContext, MODAL_TYPES } from '../components/GlobalModal'; import Loading from '../components/Loading'; -import { getGlobalWallet } from "../services/wallet.singleton"; +import { getGlobalWallet } from "../modules/wallet.singleton"; const mapStateToProps = (state) => { diff --git a/src/components/WalletAddress.js b/src/components/WalletAddress.js index c9e03d5f..ee51b28a 100644 --- a/src/components/WalletAddress.js +++ b/src/components/WalletAddress.js @@ -15,7 +15,7 @@ import { IPC_RENDERER } from '../constants'; import { sharedAddressUpdate } from '../actions/index'; import { GlobalModalContext, MODAL_TYPES } from './GlobalModal'; import LOCAL_STORE from '../storage'; -import { getGlobalWallet } from "../services/wallet.singleton"; +import { getGlobalWallet } from "../modules/wallet.singleton"; const mapDispatchToProps = dispatch => { return { diff --git a/src/components/atomic-swap/ModalAtomicReceive.js b/src/components/atomic-swap/ModalAtomicReceive.js index 1b354050..2ce4dc7d 100644 --- a/src/components/atomic-swap/ModalAtomicReceive.js +++ b/src/components/atomic-swap/ModalAtomicReceive.js @@ -10,7 +10,7 @@ import { t } from "ttag"; import InputNumber from "../InputNumber"; import hathorLib, { Address } from "@hathor/wallet-lib"; import walletUtils from '../../utils/wallet'; -import { getGlobalWallet } from "../../services/wallet.singleton"; +import { getGlobalWallet } from "../../modules/wallet.singleton"; export function ModalAtomicReceive ({ sendClickHandler, receivableTokens, manageDomLifecycle, onClose }) { /** @type HathorWallet */ diff --git a/src/components/tokens/TokenDelegate.js b/src/components/tokens/TokenDelegate.js index 7bba618d..f792afd0 100644 --- a/src/components/tokens/TokenDelegate.js +++ b/src/components/tokens/TokenDelegate.js @@ -10,7 +10,7 @@ import { t } from 'ttag'; import TokenAction from './TokenAction'; import { connect } from "react-redux"; import hathorLib from '@hathor/wallet-lib'; -import { getGlobalWallet } from "../../services/wallet.singleton"; +import { getGlobalWallet } from "../../modules/wallet.singleton"; const mapStateToProps = (state) => { return { diff --git a/src/components/tokens/TokenDestroy.js b/src/components/tokens/TokenDestroy.js index ad834dbc..7b8b35b7 100644 --- a/src/components/tokens/TokenDestroy.js +++ b/src/components/tokens/TokenDestroy.js @@ -12,7 +12,7 @@ import helpers from '../../utils/helpers'; import TokenAction from './TokenAction'; import SpanFmt from '../SpanFmt'; import { connect } from "react-redux"; -import { getGlobalWallet } from "../../services/wallet.singleton"; +import { getGlobalWallet } from "../../modules/wallet.singleton"; const mapStateToProps = (state) => { return { diff --git a/src/components/tokens/TokenMelt.js b/src/components/tokens/TokenMelt.js index 9a2ba7e0..ab5470ef 100644 --- a/src/components/tokens/TokenMelt.js +++ b/src/components/tokens/TokenMelt.js @@ -17,7 +17,7 @@ import { connect } from 'react-redux'; import { get } from 'lodash'; import { TOKEN_DOWNLOAD_STATUS } from '../../sagas/tokens'; import { colors } from '../../constants'; -import { getGlobalWallet } from "../../services/wallet.singleton"; +import { getGlobalWallet } from "../../modules/wallet.singleton"; const mapStateToProps = (state) => { return { diff --git a/src/components/tokens/TokenMint.js b/src/components/tokens/TokenMint.js index 111e489d..7b924f75 100644 --- a/src/components/tokens/TokenMint.js +++ b/src/components/tokens/TokenMint.js @@ -16,7 +16,7 @@ import helpers from '../../utils/helpers'; import InputNumber from '../InputNumber'; import { connect } from 'react-redux'; import { get } from 'lodash'; -import { getGlobalWallet } from "../../services/wallet.singleton"; +import { getGlobalWallet } from "../../modules/wallet.singleton"; const mapStateToProps = (state) => { return { diff --git a/src/services/wallet.singleton.js b/src/modules/wallet.js similarity index 69% rename from src/services/wallet.singleton.js rename to src/modules/wallet.js index 7b49d947..908b5774 100644 --- a/src/services/wallet.singleton.js +++ b/src/modules/wallet.js @@ -8,14 +8,14 @@ import hathorLib from "@hathor/wallet-lib"; /** - * - * @type {HathorWallet|null} + * Application-wide HathorWallet object + * @type {hathorLib.HathorWallet|null} */ let globalWallet = null; /** * Sets the global Hathor Wallet - * @param {HathorWallet} wallet + * @param {hathorLib.HathorWallet} wallet */ export function setGlobalWallet(wallet) { if (globalWallet && globalWallet.state !== hathorLib.HathorWallet.CLOSED) { @@ -26,11 +26,17 @@ export function setGlobalWallet(wallet) { globalWallet = wallet; } +/** + * Retrieves the application-wide HathorWallet object + */ export function getGlobalWallet() { return globalWallet; } -export function resetWallet() { +/** + * Stops the application-wide HathorWallet object and removes it from memory + */ +export function stopWallet() { if (!globalWallet) { return; } diff --git a/src/sagas/atomicSwap.js b/src/sagas/atomicSwap.js index 65c321fe..2d1a5bf9 100644 --- a/src/sagas/atomicSwap.js +++ b/src/sagas/atomicSwap.js @@ -26,7 +26,7 @@ import { } from "../utils/atomicSwap"; import { t } from "ttag"; import { swapService } from '@hathor/wallet-lib' -import { getGlobalWallet } from "../services/wallet.singleton"; +import { getGlobalWallet } from "../modules/wallet.singleton"; const CONCURRENT_FETCH_REQUESTS = 5; diff --git a/src/sagas/tokens.js b/src/sagas/tokens.js index e58ee1d8..05a9aa1d 100644 --- a/src/sagas/tokens.js +++ b/src/sagas/tokens.js @@ -26,7 +26,7 @@ import { proposalTokenFetchFailed, } from '../actions'; import { t } from "ttag"; -import { getGlobalWallet } from "../services/wallet.singleton"; +import { getGlobalWallet } from "../modules/wallet.singleton"; const CONCURRENT_FETCH_REQUESTS = 5; const METADATA_MAX_RETRIES = 3; diff --git a/src/sagas/wallet.js b/src/sagas/wallet.js index a0327b9d..e828e13f 100644 --- a/src/sagas/wallet.js +++ b/src/sagas/wallet.js @@ -71,7 +71,7 @@ import { fetchTokenData } from './tokens'; import walletUtils from '../utils/wallet'; import tokensUtils from '../utils/tokens'; import { initializeSwapServiceBaseUrlForWallet } from "../utils/atomicSwap"; -import { getGlobalWallet, setGlobalWallet } from "../services/wallet.singleton"; +import { getGlobalWallet, setGlobalWallet } from "../modules/wallet.singleton"; export const WALLET_STATUS = { READY: 'ready', diff --git a/src/screens/AddressList.js b/src/screens/AddressList.js index b9748a16..db3efa8f 100644 --- a/src/screens/AddressList.js +++ b/src/screens/AddressList.js @@ -13,7 +13,7 @@ import { WALLET_HISTORY_COUNT } from '../constants'; import helpers from '../utils/helpers'; import walletUtils from '../utils/wallet'; import path from 'path'; -import { getGlobalWallet } from "../services/wallet.singleton"; +import { getGlobalWallet } from "../modules/wallet.singleton"; /** * Screen that has a list of addresses of the wallet diff --git a/src/screens/ChoosePassphrase.js b/src/screens/ChoosePassphrase.js index b0068c97..fb12d212 100644 --- a/src/screens/ChoosePassphrase.js +++ b/src/screens/ChoosePassphrase.js @@ -13,7 +13,7 @@ import walletUtils from '../utils/wallet'; import BackButton from '../components/BackButton'; import { GlobalModalContext, MODAL_TYPES } from '../components/GlobalModal'; import { useNavigate } from 'react-router-dom'; -import { getGlobalWallet } from "../services/wallet.singleton"; +import { getGlobalWallet } from "../modules/wallet.singleton"; /** * Screen used to choose a passphrase for your wallet diff --git a/src/screens/CreateNFT.js b/src/screens/CreateNFT.js index 78ffe69d..83544768 100644 --- a/src/screens/CreateNFT.js +++ b/src/screens/CreateNFT.js @@ -23,7 +23,7 @@ import { NFT_DATA_MAX_SIZE, NFT_GUIDE_URL, NFT_STANDARD_RFC_URL } from '../const import InputNumber from '../components/InputNumber'; import { GlobalModalContext, MODAL_TYPES } from '../components/GlobalModal'; import { useNavigate } from 'react-router-dom'; -import { getGlobalWallet } from "../services/wallet.singleton"; +import { getGlobalWallet } from "../modules/wallet.singleton"; /** diff --git a/src/screens/CreateToken.js b/src/screens/CreateToken.js index aefbd27d..e5c78c6d 100644 --- a/src/screens/CreateToken.js +++ b/src/screens/CreateToken.js @@ -23,7 +23,7 @@ import InputNumber from '../components/InputNumber'; import { GlobalModalContext, MODAL_TYPES } from '../components/GlobalModal'; import { str2jsx } from '../utils/i18n'; import { useNavigate } from "react-router-dom"; -import { getGlobalWallet } from "../services/wallet.singleton"; +import { getGlobalWallet } from "../modules/wallet.singleton"; /** * Create a new token diff --git a/src/screens/SendTokens.js b/src/screens/SendTokens.js index 13dc525f..360f8f79 100644 --- a/src/screens/SendTokens.js +++ b/src/screens/SendTokens.js @@ -21,7 +21,7 @@ import ReactLoading from 'react-loading'; import { GlobalModalContext, MODAL_TYPES } from '../components/GlobalModal'; import LOCAL_STORE from '../storage'; import { useNavigate } from 'react-router-dom'; -import { getGlobalWallet } from "../services/wallet.singleton"; +import { getGlobalWallet } from "../modules/wallet.singleton"; /** @typedef {0|1} LEDGER_MODAL_STATE */ const LEDGER_MODAL_STATE = { diff --git a/src/screens/Server.js b/src/screens/Server.js index 3017dc1e..cc4b978f 100644 --- a/src/screens/Server.js +++ b/src/screens/Server.js @@ -21,7 +21,7 @@ import { import { useDispatch, useSelector } from 'react-redux'; import { GlobalModalContext, MODAL_TYPES } from '../components/GlobalModal'; import LOCAL_STORE from '../storage'; -import { getGlobalWallet } from "../services/wallet.singleton"; +import { getGlobalWallet } from "../modules/wallet.singleton"; import { useNavigate } from 'react-router-dom'; import { isVersionAllowedUpdate, selectToken } from "../actions"; diff --git a/src/screens/TransactionDetail.js b/src/screens/TransactionDetail.js index dcff8e11..595168c5 100644 --- a/src/screens/TransactionDetail.js +++ b/src/screens/TransactionDetail.js @@ -15,7 +15,7 @@ import { colors } from '../constants'; import helpers from '../utils/helpers'; import path from 'path'; import { useNavigate, useParams } from 'react-router-dom'; -import { getGlobalWallet } from "../services/wallet.singleton"; +import { getGlobalWallet } from "../modules/wallet.singleton"; /** * Shows the detail of a transaction or block diff --git a/src/screens/Wallet.js b/src/screens/Wallet.js index 61a3e92a..0c7f450b 100644 --- a/src/screens/Wallet.js +++ b/src/screens/Wallet.js @@ -29,7 +29,7 @@ import { GlobalModalContext, MODAL_TYPES } from '../components/GlobalModal'; import { tokenFetchBalanceRequested, tokenFetchHistoryRequested, updateWords, } from '../actions/index'; import LOCAL_STORE from '../storage'; import { useNavigate } from 'react-router-dom'; -import { getGlobalWallet } from "../services/wallet.singleton"; +import { getGlobalWallet } from "../modules/wallet.singleton"; /** diff --git a/src/screens/atomic-swap/EditSwap.js b/src/screens/atomic-swap/EditSwap.js index bcfa20ee..4d1316b1 100644 --- a/src/screens/atomic-swap/EditSwap.js +++ b/src/screens/atomic-swap/EditSwap.js @@ -27,7 +27,7 @@ import { cloneDeep, get } from 'lodash'; import { TOKEN_DOWNLOAD_STATUS } from "../../sagas/tokens"; import Loading from "../../components/Loading"; import { proposalTokenFetchRequested } from "../../actions"; -import { getGlobalWallet } from "../../services/wallet.singleton"; +import { getGlobalWallet } from "../../modules/wallet.singleton"; /** * @param {string} props.match.params.proposalId Proposal identifier diff --git a/src/screens/atomic-swap/NewSwap.js b/src/screens/atomic-swap/NewSwap.js index b5afd5e8..f67c9034 100644 --- a/src/screens/atomic-swap/NewSwap.js +++ b/src/screens/atomic-swap/NewSwap.js @@ -13,7 +13,7 @@ import { } from "../../utils/atomicSwap"; import { useDispatch, useSelector } from "react-redux"; import { proposalCreateRequested } from "../../actions"; -import { getGlobalWallet } from "../../services/wallet.singleton"; +import { getGlobalWallet } from "../../modules/wallet.singleton"; export default function NewSwap (props) { const [password, setPassword] = useState(''); diff --git a/src/utils/tokens.js b/src/utils/tokens.js index 91a980b8..138754fc 100644 --- a/src/utils/tokens.js +++ b/src/utils/tokens.js @@ -10,7 +10,7 @@ import { newTokens, removeTokenMetadata } from '../actions/index'; import wallet from './wallet'; import hathorLib from '@hathor/wallet-lib'; import LOCAL_STORE from '../storage'; -import { getGlobalWallet } from "../services/wallet.singleton"; +import { getGlobalWallet } from "../modules/wallet.singleton"; /** * Methods to create and handle tokens