Skip to content

Commit

Permalink
refactor: services to modules folder
Browse files Browse the repository at this point in the history
  • Loading branch information
tuliomir committed Apr 16, 2024
1 parent 6bb3122 commit 91d18c4
Show file tree
Hide file tree
Showing 31 changed files with 40 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ModalAddManyTokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/components/ModalAddToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/components/ModalBackupWords.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ModalPin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/components/ModalResetAllData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/components/ModalSendTx.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ModalUnregisteredTokenInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/components/TokenHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/TxData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/WalletAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/components/atomic-swap/ModalAtomicReceive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/components/tokens/TokenDelegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/components/tokens/TokenDestroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/components/tokens/TokenMelt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/components/tokens/TokenMint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 10 additions & 4 deletions src/services/wallet.singleton.js → src/modules/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/sagas/atomicSwap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/sagas/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/sagas/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/screens/AddressList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/screens/ChoosePassphrase.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/screens/CreateNFT.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";


/**
Expand Down
2 changes: 1 addition & 1 deletion src/screens/CreateToken.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/screens/SendTokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
2 changes: 1 addition & 1 deletion src/screens/TransactionDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";


/**
Expand Down
2 changes: 1 addition & 1 deletion src/screens/atomic-swap/EditSwap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/screens/atomic-swap/NewSwap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
Expand Down
2 changes: 1 addition & 1 deletion src/utils/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 91d18c4

Please sign in to comment.