Skip to content

Commit

Permalink
feat: refactor imports to use initCommon across multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
vuonghuuhung committed Dec 2, 2024
1 parent 200ddf6 commit e1d3d9f
Show file tree
Hide file tree
Showing 83 changed files with 206 additions and 220 deletions.
9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@oraichain/orai-bitcoin": "2.0.0",
"@oraichain/oraidex-common-ui": "1.0.11",
"@oraichain/oraidex-contracts-sdk": "1.0.55",
"@oraichain/oraidex-universal-swap": "1.1.23",
"@oraichain/oraidex-universal-swap": "1.2.0-beta4",
"@react-spring/web": "^9.7.5",
"@reduxjs/toolkit": "^1.9.3",
"@sentry/react": "7.99.0",
Expand Down Expand Up @@ -83,7 +83,7 @@
"@oraichain/common-contracts-build": "1.0.35",
"@oraichain/cw-simulate": "^2.8.108",
"@oraichain/oraidex-contracts-build": "1.0.22",
"@oraichain/oraiswap-v3": "^1.1.2",
"@oraichain/oraiswap-v3": "1.2.0-beta4",
"@sentry/webpack-plugin": "^2.10.3",
"@testing-library/jest-dom": "^6.5.0",
"@types/classnames": "^2.2.10",
Expand Down Expand Up @@ -114,8 +114,7 @@
"vite-plugin-node-polyfills": "^0.22.0",
"vite": "^5.4.10",
"vite-plugin-wasm": "^3.3.0",
"vitest": "2.0.2",
"@oraichain/oraidex-common": "2.0.0-beta.1"
"vitest": "2.0.2"
},
"scripts": {
"analyze": "source-map-explorer 'build/static/js/*.js'",
Expand Down Expand Up @@ -151,7 +150,7 @@
"bitcoinjs-lib": "5.2.0",
"axios": "0.26.1",
"@sentry/react": "7.99.0",
"@oraichain/oraidex-common": "2.0.0-beta.1",
"@oraichain/oraidex-common": "2.0.0-beta.3",
"@cosmjs/amino": "0.32.4"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion src/components/LuckyDraw/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import Lottie from 'lottie-react';
import InputRange from 'pages/CoHarvest/components/InputRange';
import { numberWithCommas } from 'pages/Pools/helpers';
import { Spin } from './luckyDrawClient/LuckyWheelContract.types';
import { network } from 'index';
import { network } from 'initCommon';

const LuckyDraw: FC<{}> = () => {
const [address] = useConfigReducer('address');
Expand Down
2 changes: 1 addition & 1 deletion src/components/LuckyDraw/useLuckyDraw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { LUCKY_DRAW_CONTRACT, LUCKY_DRAW_FEE, FETCH_RESULT_INTERVAL, MAX_SPIN_TI
import { MulticallQueryClient } from '@oraichain/common-contracts-sdk';
import { fromBinary, toBinary } from '@cosmjs/cosmwasm-stargate';
import { Spin } from './luckyDrawClient/LuckyWheelContract.types';
import { network } from 'index';
import { network } from 'initCommon';

export const getDataLogByKey = (log: any, key: string) => {
const events = log?.events || [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import GooglePlayOWalletDarkIcon from 'assets/icons/google_play_owallet_dark.svg
import DownloadOwalletIcon from 'assets/icons/logo_owallet_gateway.svg?react';
import DownloadOwalletIconDark from 'assets/icons/logo_owallet_gateway_dark.svg?react';
import classNames from 'classnames';
import Modal from 'components/Modal';
import useTheme from 'hooks/useTheme';
import QRCode from 'qrcode';
import { useEffect, useState } from 'react';
import styles from './ModalDownloadOwallet.module.scss';
import Modal from 'components/Modal';
import { owalletAndroidDownloadUrl, owalletExtensionDownloadUrl, owalletIosDownloadUrl } from 'pages/DownloadApp';

const ModalDownloadOwallet: React.FC<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import styles from './SelectTokenModal.module.scss';
import useConfigReducer from 'hooks/useConfigReducer';
import { CustomChainInfo, TokenItemType, getSubAmountDetails, truncDecimals } from '@oraichain/oraidex-common';
import { chainIcons, tokensIcon } from 'config/chainInfos';
import { tokenMap } from 'index';
import { tokenMap } from 'initCommon';

const cx = cn.bind(styles);

Expand Down
8 changes: 4 additions & 4 deletions src/components/WalletManagement/WalletManagement.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { isMobile } from '@walletconnect/browser-utils';
import cn from 'classnames/bind';
import { Button } from 'components/Button';
import { keplrCheck } from 'helper';
import styles from './WalletManagement.module.scss';
import useConfigReducer from 'hooks/useConfigReducer';
import useLoadTokens from 'hooks/useLoadTokens';
import { useInactiveConnect } from 'hooks/useMetamask';
import useWalletReducer from 'hooks/useWalletReducer';
import { FC, useEffect, useState } from 'react';
import Connected from './Connected';
import { ConnectedMobile } from './ConnectedMobile';
import { ModalChooseWallet } from './ModalChooseWallet';
import { MyWallet } from './MyWallet';
import { MyWalletMobile } from './MyWalletMobile';
import styles from './WalletManagement.module.scss';
import type { Wallet as WalletResetType } from './useResetBalance';
import { useResetBalance } from './useResetBalance';
import { WalletNetwork, WalletProvider, walletProvider } from './walletConfig';
import Connected from './Connected';
import { keplrCheck } from 'helper';
import { useResetBalance } from './useResetBalance';
const cx = cn.bind(styles);

export const WalletManagement: FC<{}> = () => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/WalletManagement/useResetBalance.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EVM_CHAIN_ID_COMMON, WalletType } from '@oraichain/oraidex-common';
import { cosmosTokens, flattenTokens } from 'index';
import { cosmosTokens, flattenTokens } from 'initCommon';
import { btcTokens } from 'config/bridgeTokens';
import { useDispatch } from 'react-redux';
import { updateAmounts } from 'reducer/token';
Expand Down
1 change: 0 additions & 1 deletion src/config/bridgeTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
} from '@oraichain/oraidex-common';
import { bitcoinChainId } from 'helper/constants';
import { flattenTokens, oraichainTokens, otherChainTokens } from 'initCommon';
// import { flattenTokens, oraichainTokens, otherChainTokens } from 'index';

const evmDenomsMap = {
kwt: [KWTBSC_ORAICHAIN_DENOM],
Expand Down
1 change: 0 additions & 1 deletion src/config/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { PAIRS, TokenItemType, parseAssetInfo, USDC_CONTRACT, ORAIX_CONTRACT } f
import uniq from 'lodash/uniq';
import flatten from 'lodash/flatten';
import { assetInfoMap } from 'initCommon';
// import { assetInfoMap } from 'index';

export const getPoolTokens = (): TokenItemType[] => {
return (
Expand Down
1 change: 0 additions & 1 deletion src/helper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
EVM_CHAIN_ID_COMMON,
WalletType as WalletCosmosType
} from '@oraichain/oraidex-common';
// import { cosmosChains, evmChains, network } from 'index';
import { serializeError } from 'serialize-error';
import { fromBech32, toBech32 } from '@cosmjs/encoding';
import { bitcoinChainId, leapSnapId } from './constants';
Expand Down
1 change: 0 additions & 1 deletion src/hooks/useCoingecko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { useQuery } from '@tanstack/react-query';
import useConfigReducer from './useConfigReducer';
import { CoinGeckoId } from '@oraichain/oraidex-common';
import { cosmosTokens, evmTokens } from 'initCommon';
// import { cosmosTokens, evmTokens } from 'index';

/**
* Constructs the URL to retrieve prices from CoinGecko.
Expand Down
30 changes: 14 additions & 16 deletions src/hooks/useLoadTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,35 @@ import { fromBinary, toBinary } from '@cosmjs/cosmwasm-stargate';
import { StargateClient } from '@cosmjs/stargate';
import { MulticallQueryClient } from '@oraichain/common-contracts-sdk';
import { OraiswapTokenTypes } from '@oraichain/oraidex-contracts-sdk';
import { btcTokens } from 'config/bridgeTokens';
import { cosmosTokens, evmTokens, network, oraichainTokens, tokenMap } from 'index';
import {
genAddressCosmos,
getAddress,
handleCheckWallet,
getWalletByNetworkCosmosFromStorage,
handleErrorRateLimit
} from 'helper';
import { cosmosTokens, evmTokens, network, oraichainTokens, tokenMap } from 'initCommon';
import flatten from 'lodash/flatten';
import { updateAmounts } from 'reducer/token';
import { ContractCallResults, Multicall } from '@oraichain/ethereum-multicall';
import { generateError } from '../libs/utils';
import { COSMOS_CHAIN_ID_COMMON } from '@oraichain/oraidex-common';
import { Dispatch } from '@reduxjs/toolkit';
import { useDispatch } from 'react-redux';

import {
CustomChainInfo,
EVM_BALANCE_RETRY_COUNT,
ERC20__factory,
getEvmAddress,
tronToEthAddress
} from '@oraichain/oraidex-common';
import { UniversalSwapHelper } from '@oraichain/oraidex-universal-swap';
import { chainInfos, evmChains } from 'config/chainInfos';
import { ethers } from 'ethers';
import axios from 'rest/request';
import { reduce } from 'lodash';
import { getUtxos } from 'pages/Balance/helpers';
import { bitcoinChainId } from 'helper/constants';
import { getUtxos } from 'pages/Balance/helpers';
import { btcTokens } from 'config/bridgeTokens';
import { chainInfos, evmChains } from 'config/chainInfos';
import { generateError } from '../libs/utils';
import { updateAmounts } from 'reducer/token';
import {
genAddressCosmos,
getAddress,
handleCheckWallet,
getWalletByNetworkCosmosFromStorage,
handleErrorRateLimit
} from 'helper';
import { UniversalSwapHelper } from '@oraichain/oraidex-universal-swap';

export type LoadTokenParams = {
refresh?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useTokenFee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { useDispatch, useSelector } from 'react-redux';
import { updateFeeConfig } from 'reducer/token';
import { fetchFeeConfig } from 'rest/api';
import { RootState } from 'store/configure';
import { network, oraichainTokens } from 'index';
import { network, oraichainTokens } from 'initCommon';

export default function useTokenFee(
remoteTokenDenom: string,
Expand Down
9 changes: 3 additions & 6 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// import 'initCommon';
console.log('Hello from src/index.tsx');
import { HttpClient, Tendermint37Client, WebsocketClient } from '@cosmjs/tendermint-rpc';
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate';
Expand All @@ -15,13 +14,11 @@ import { persistor, store } from 'store/configure';
import 'react-toastify/dist/ReactToastify.css';
import './index.scss';
import ScrollToTop from './layouts/ScrollToTop';
import { OraidexCommon } from '@oraichain/oraidex-common';

import { EVM_CHAIN_ID, getWalletByNetworkCosmosFromStorage } from 'helper';
import { getWalletByNetworkCosmosFromStorage } from 'helper';
import { getCosmWasmClient } from 'libs/cosmjs';
import 'polyfill';
import App from './layouts/App';
import { network, oraichainTokens } from 'initCommon';
import { network } from 'initCommon';

// const client = new Client({
// url: 'http://10.10.20.72:3000/',
Expand Down Expand Up @@ -76,7 +73,7 @@ const initApp = async () => {
<Router>
<ScrollToTop />
<QueryClientProvider client={queryClient}>
{/* <App /> */}
<App />
</QueryClientProvider>
</Router>
<ToastContext.Consumer>
Expand Down
9 changes: 5 additions & 4 deletions src/layouts/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import { TToastType, displayToast } from 'components/Toasts/Toast';
import { ThemeProvider } from 'context/theme-context';
import { getListAddressCosmos, interfaceRequestTron } from 'helper';
import useConfigReducer from 'hooks/useConfigReducer';
import useLoadTokens from 'hooks/useLoadTokens';
import { useTronEventListener } from 'hooks/useTronLink';
import useWalletReducer from 'hooks/useWalletReducer';
import { network } from 'index';
import SingletonOraiswapV3 from 'libs/contractSingleton';
import { getCosmWasmClient } from 'libs/cosmjs';
import Keplr from 'libs/keplr';
Expand All @@ -21,11 +18,15 @@ import { useEffect, useState } from 'react';
import { useDispatch } from 'react-redux';
import useWebSocket from 'react-use-websocket';
import { setAddressBookList } from 'reducer/addressBook';
import routes from 'routes';
import { persistor } from 'store/configure';
import { ADDRESS_BOOK_KEY_BACKUP, PERSIST_VER } from 'store/constants';
import './index.scss';
import { network } from 'initCommon';
import useLoadTokens from 'hooks/useLoadTokens';
import { useTronEventListener } from 'hooks/useTronLink';
import Menu from './Menu';

import routes from 'routes';
import { NoticeBanner } from './NoticeBanner';
import Sidebar from './Sidebar';

Expand Down
6 changes: 2 additions & 4 deletions src/layouts/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,22 @@ import IconOrderbookHLW from 'assets/icons/halloween/ic_orderbook_hlw.svg';
import MenuIcon from 'assets/icons/menu.svg?react';
import LogoFullImgDark from 'assets/images/OraiDEX_full_dark.svg';
import LogoFullImgLight from 'assets/images/OraiDEX_full_light.svg';

import LogoFullImgDarkBeta from 'assets/images/OraiDEX_logo_dark.svg';
import LogoFullImgLightBeta from 'assets/images/OraiDEX_logo_light.svg';

import PoolV3Lottie from 'assets/lottie/poolv3-beta.json';
import classNames from 'classnames';
import TooltipContainer from 'components/WalletManagement/TooltipContainer';
import { WalletManagement } from 'components/WalletManagement/WalletManagement';
import { EVENT_CONFIG_THEME } from 'config/eventConfig';
import { ThemeContext } from 'context/theme-context';
import useOnClickOutside from 'hooks/useOnClickOutside';
import useTemporaryConfigReducer from 'hooks/useTemporaryConfigReducer';
import Lottie from 'lottie-react';
import React, { ReactNode, useContext, useEffect, useRef, useState } from 'react';
import { Link, useLocation } from 'react-router-dom';
import BuyOraiModal from './BuyOraiModal';
import styles from './Menu.module.scss';
import BuyOraiModal from './BuyOraiModal';
import { EVENT_ENUM } from 'reducer/temporaryConfig';
import { WalletManagement } from 'components/WalletManagement/WalletManagement';

const Menu: React.FC = () => {
const location = useLocation();
Expand Down
8 changes: 4 additions & 4 deletions src/layouts/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import DownloadOwalletIconDark from 'assets/icons/logo_owallet_gateway_dark.svg?
import PoolV3Icon from 'assets/icons/pool-v3.svg?react';
import PoolV3Lottie from 'assets/lottie/poolv3-beta.json';
import classNames from 'classnames';
import ModalDownloadOwallet from 'components/Modals/ModalDownloadOwallet/ModalDownloadOwallet';
import { EVENT_CONFIG_THEME } from 'config/eventConfig';
import useTemporaryConfigReducer from 'hooks/useTemporaryConfigReducer';
import useTheme from 'hooks/useTheme';
import React, { ReactElement, useEffect, useState } from 'react';
import { Link, useLocation } from 'react-router-dom';
import styles from './Sidebar.module.scss';
import useTheme from 'hooks/useTheme';
import { EVENT_CONFIG_THEME } from 'config/eventConfig';
import Lottie from 'lottie-react';
import useTemporaryConfigReducer from 'hooks/useTemporaryConfigReducer';
import ModalDownloadOwallet from 'components/Modals/ModalDownloadOwallet/ModalDownloadOwallet';

const Sidebar: React.FC<{}> = React.memo(() => {
const location = useLocation();
Expand Down
1 change: 0 additions & 1 deletion src/libs/bitcoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Key } from '@keplr-wallet/types';

import { bitcoinChainId } from 'helper/constants';
import { network } from 'initCommon';
// import { network } from 'index';
export type BitcoinMode = 'core' | 'extension' | 'mobile-web' | 'walletconnect';
// import { CosmosChainId, BitcoinWallet } from '@oraichain/oraidex-common';
type BitcoinChainId = 'bitcoin' | 'bitcoinTestnet';
Expand Down
1 change: 0 additions & 1 deletion src/libs/cosmjs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Coin, GasPrice } from '@cosmjs/stargate';
import { Tendermint37Client } from '@cosmjs/tendermint-rpc';
import { Stargate } from '@injectivelabs/sdk-ts';
import { getWalletByNetworkCosmosFromStorage } from 'helper';
// import { network } from 'index';
import { MetamaskOfflineSigner } from './eip191';
import { network } from 'initCommon';
export type clientType = 'cosmwasm' | 'injective';
Expand Down
1 change: 0 additions & 1 deletion src/libs/keplr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { isMobile } from '@walletconnect/browser-utils';
import { displayToast, TToastType } from 'components/Toasts/Toast';
import { chainInfos, OraiBTCBridgeNetwork } from 'config/chainInfos';
import { getAddress, getAddressByEIP191 } from 'helper';
// import { network } from 'index';
import { EIP_EIP_STORAGE_KEY_ACC, MetamaskOfflineSigner } from './eip191';
import { network } from 'initCommon';

Expand Down
1 change: 0 additions & 1 deletion src/libs/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import bech32 from 'bech32';
import { chainInfos } from 'config/chainInfos';
import { CoinGeckoPrices } from 'hooks/useCoingecko';
import { cosmosTokens, network, tokenMap } from 'initCommon';
// import { cosmosTokens, network, tokenMap } from 'index';
import { getCosmWasmClient } from 'libs/cosmjs';

export const checkRegex = (str: string, regex?: RegExp) => {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Balance/DepositBtcModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { useCopy } from 'hooks/useCopy';
import { Link } from 'react-router-dom';
import { BigDecimal, CoinGeckoPrices } from '@oraichain/oraidex-common';
import { useRelayerFeeToken } from 'hooks/useTokenFee';
import { flattenTokens } from 'index';
import { flattenTokens } from 'initCommon';

interface ModalProps {
isOpen: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Balance/DepositBtcModalV2/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Link } from 'react-router-dom';
import { BigDecimal, CoinGeckoPrices } from '@oraichain/oraidex-common';
import { useRelayerFeeToken } from 'hooks/useTokenFee';
import { CwBitcoinContext } from 'context/cw-bitcoin-context';
import { flattenTokens } from 'index';
import { flattenTokens } from 'initCommon';

interface ModalProps {
isOpen: boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Balance/StuckOraib/useGetOraiBridgeBalances.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import uniqBy from 'lodash/uniqBy';
import { useEffect, useState } from 'react';
import { useSelector } from 'react-redux';
import { RootState } from 'store/configure';
import { cosmosTokens } from 'index';
import { cosmosTokens } from 'initCommon';

export type RemainingOraibTokenItem = TokenItemType & { amount: string };
export default function useGetOraiBridgeBalances(moveOraib2OraiLoading: boolean) {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Balance/TransferConvertToken/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import styles from './index.module.scss';
import { useGetContractConfig } from 'pages/BitcoinDashboardV2/hooks';
import ToggleSwitch from 'components/ToggleSwitch';
import { CWBitcoinFactoryDenom } from 'helper/constants';
import { cosmosTokens, flattenTokens, tokenMap } from 'index';
import { cosmosTokens, flattenTokens, tokenMap } from 'initCommon';

interface TransferConvertProps {
token: TokenItemType;
Expand Down
3 changes: 1 addition & 2 deletions src/pages/Balance/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
} from '@oraichain/oraidex-common';
import { chainInfos } from 'config/chainInfos';
import { feeEstimate, getNetworkGasPrice } from 'helper';
import { network } from 'index';

import { CwIcs20LatestClient } from '@oraichain/common-contracts-sdk';
import { TransferBackMsg } from '@oraichain/common-contracts-sdk/build/CwIcs20Latest.types';
Expand All @@ -36,7 +35,7 @@ import {
bitcoinLcd,
bitcoinLcdV2
} from 'helper/constants';
import { flattenTokens, kawaiiTokens, tokenMap } from 'index';
import { flattenTokens, kawaiiTokens, tokenMap, network } from 'initCommon';
import CosmJs, { collectWallet, connectWithSigner, getCosmWasmClient } from 'libs/cosmjs';
import KawaiiverseJs from 'libs/kawaiiversejs';
import { NomicClient } from 'libs/nomic/models/nomic-client/nomic-client';
Expand Down
Loading

0 comments on commit e1d3d9f

Please sign in to comment.