diff --git a/package.json b/package.json index 0d17c2d..675b3fe 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "commit-hook": "git add .", "lint": "eslint './src/**/*.ts{,x}' --fix", "prettier": "prettier --write \"**/*.+(ts|tsx)\"", - "watch": "webpack --env NODE_ENV=production --watch --progress --mode=production", + "watch": "webpack --env NODE_ENV=development --watch --progress --mode=development", "serve": "webpack serve --mode=development", "build": "webpack --env NODE_ENV=production --mode=production" }, @@ -65,7 +65,7 @@ "@types/readable-stream": "^2.3.11", "@unstoppabledomains/resolution": "^8.3.3", "babel-polyfill": "^6.26.0", - "beam-wasm-client": "7.3.14073", + "beam-wasm-client": "7.3.13743", "browser-passworder": "^2.0.3", "buffer": "^6.0.3", "dnode": "^1.2.2", diff --git a/src/app/config.ts b/src/app/config.ts index 0c70ed9..3a53525 100644 --- a/src/app/config.ts +++ b/src/app/config.ts @@ -9,7 +9,8 @@ const development: Configuration = { explorer_url: 'https://dappnet.explorer.beam.mw/block?kernel_id=', restore_url: 'https://mobile-restore.beam.mw/dappnet/dappnet_recovery.bin', theme: 'dappnet', - dex_url: 'https://dappnet-dex.beam.mw"', + dex_url: 'https://dappnet-dex.beam.mw', + network: 'dappnet', }; const master_net: Configuration = { @@ -17,6 +18,7 @@ const master_net: Configuration = { path_node: 'eu-node01.masternet.beam.mw:8200', theme: 'masternet', explorer_url_confidential_id: 'https://master-net.explorer.beam.mw/assets/details/', + network: 'masternet', }; const test_net: Configuration = { @@ -26,6 +28,7 @@ const test_net: Configuration = { path_node: 'eu-node01.testnet.beam.mw:8200', theme: 'testnet', explorer_url_confidential_id: 'https://testnet.explorer.beam.mw/assets/details/', + network: 'testnet', }; const main_net: Configuration = { @@ -36,6 +39,7 @@ const main_net: Configuration = { theme: 'mainnet', explorer_url_confidential_id: 'https://explorer.beam.mw/assets/details/', dex_url: 'https://dex.beam.mw', + network: 'mainnet', }; const dapp_net: Configuration = { @@ -44,6 +48,7 @@ const dapp_net: Configuration = { explorer_url: 'https://dappnet.explorer.beam.mw/block?kernel_id=', restore_url: 'https://mobile-restore.beam.mw/dappnet/dappnet_recovery.bin', theme: 'dappnet', + network: 'dappnet', }; const production: Configuration = { diff --git a/src/app/containers/Wallet/containers/Wallet/Wallet.tsx b/src/app/containers/Wallet/containers/Wallet/Wallet.tsx index 4d19371..2043e1a 100644 --- a/src/app/containers/Wallet/containers/Wallet/Wallet.tsx +++ b/src/app/containers/Wallet/containers/Wallet/Wallet.tsx @@ -1,17 +1,19 @@ import React, { useCallback, useEffect } from 'react'; -import { Window, Section, WalletActions } from '@app/shared/components'; +import { + Window, Section, WalletActions, Loader, +} from '@app/shared/components'; import { useNavigate } from 'react-router-dom'; import { ROUTES } from '@app/shared/constants'; import { useDispatch, useSelector } from 'react-redux'; -import { selectAssets, selectAssetsInfo, selectRate } from '@app/containers/Wallet/store/selectors'; +import { selectAssets, selectRate } from '@app/containers/Wallet/store/selectors'; -import { loadRate, getAssetList, getAssetInfo } from '@app/containers/Wallet/store/actions'; +import { loadRate, getAssetList } from '@app/containers/Wallet/store/actions'; import { TransactionList } from '@app/containers/Transactions'; import { createdComparator } from '@core/utils'; import { selectTransactions } from '@app/containers/Transactions/store/selectors'; -import { selectIsBalanceHidden, selectAssetSync } from '@app/shared/store/selectors'; +import { selectIsBalanceHidden, selectAssetSync, selectIsLoading } from '@app/shared/store/selectors'; import { Assets } from '../../components/Wallet'; const TXS_MAX = 4; @@ -20,27 +22,33 @@ const Wallet = () => { const dispatch = useDispatch(); const navigate = useNavigate(); const assets = useSelector(selectAssets()); - const assets_info = useSelector(selectAssetsInfo()); const transactions = useSelector(selectTransactions()); const isBalanceHidden = useSelector(selectIsBalanceHidden()); const isAssetSynced = useSelector(selectAssetSync()); + const isLoading = useSelector(selectIsLoading()); const rate = useSelector(selectRate()); - useEffect(() => { - const a = assets - .filter((item1) => !assets_info.some((item2) => item2.asset_id === item1.asset_id)) - .filter((ass) => ass.asset_id !== 0); - - if (a.length > 0) { - a.forEach((asset) => { - dispatch(getAssetInfo.request(asset.asset_id)); - }); - } - }, []); + // useEffect(() => { + // if (!isAssetsRequested && assets.length) { + // setTimeout(() => { + // const a = assets + // .filter((item1) => !assets_info.some((item2) => item2.asset_id === item1.asset_id)) + // .filter((ass) => ass.asset_id !== 0); + // + // if (a.length) { + // const ids = a.map((a) => a.asset_id); + // dispatch(getAssetInfo.request(ids)); + // } + // }, 10000); + // setIsAssetsRequested(true); + // } + // }, [assets, assets_info, isAssetsRequested]); useEffect(() => { if (!isAssetSynced) { - dispatch(getAssetList.request({ refresh: true })); + setTimeout(() => { + dispatch(getAssetList.request({ refresh: true })); + }, 10000); } }, [dispatch, isAssetSynced]); @@ -65,6 +73,8 @@ const Wallet = () => { return ( + {isLoading && } +
TXS_MAX ? navigateToAssets : undefined}>
diff --git a/src/app/containers/Wallet/store/actions.ts b/src/app/containers/Wallet/store/actions.ts index dbdcbb8..392d178 100644 --- a/src/app/containers/Wallet/store/actions.ts +++ b/src/app/containers/Wallet/store/actions.ts @@ -58,7 +58,7 @@ export const getAssetInfo = createAsyncAction( WalletActionTypes.GET_ASSET_INFO, WalletActionTypes.GET_ASSET_INFO_SUCCESS, WalletActionTypes.GET_ASSET_INFO_FAILURE, -)(); +)(); export const getAssetList = createAsyncAction( WalletActionTypes.GET_ASSET_LIST, diff --git a/src/app/containers/Wallet/store/reducer.ts b/src/app/containers/Wallet/store/reducer.ts index 337769d..e6a2a0d 100644 --- a/src/app/containers/Wallet/store/reducer.ts +++ b/src/app/containers/Wallet/store/reducer.ts @@ -74,17 +74,19 @@ const handleAssets = (state: WalletStateType) => { : []; }; +const filterAssets = (assets: Asset[]) => assets.filter((asset, index, self) => index === self.findIndex((t) => t.asset_id === asset.asset_id)); + const reducer = createReducer(initialState) .handleAction(actions.setTotals, (state, action) => produce(state, (nexState) => { nexState.totals = action.payload; nexState.assets_total = handleAssets(nexState); })) .handleAction(actions.setAssets, (state, action) => produce(state, (nexState) => { - nexState.assets = action.payload; + nexState.assets = filterAssets([...action.payload, ...state.assets]); nexState.assets_total = handleAssets(nexState); })) .handleAction(actions.getAssetInfo.success, (state, action) => produce(state, (nexState) => { - nexState.assets = [...state.assets, action.payload]; + nexState.assets = filterAssets([...action.payload, ...state.assets]); })) .handleAction(actions.loadRate.success, (state, action) => produce(state, (nexState) => { nexState.rate = action.payload; diff --git a/src/app/containers/Wallet/store/saga.ts b/src/app/containers/Wallet/store/saga.ts index e00f718..93af155 100644 --- a/src/app/containers/Wallet/store/saga.ts +++ b/src/app/containers/Wallet/store/saga.ts @@ -1,6 +1,4 @@ -import { - call, put, takeEvery, takeLatest, -} from 'redux-saga/effects'; +import { call, put, takeLatest } from 'redux-saga/effects'; import { getWalletStatus, createAddress, @@ -8,15 +6,15 @@ import { calculateChange, sendTransaction, convertTokenToJson, - getAssetInfo, getAssetList, + getAssetsInfo, } from '@core/api'; import { AddressData, ChangeData, AssetsEvent, Asset, } from '@core/types'; import { RateResponse } from '@app/containers/Wallet/interfaces'; import { resetSendData } from '@app/containers/Wallet/store/actions'; -import { navigate, setAssetSync } from '@app/shared/store/actions'; +import { navigate, setAssetSync, setIsLoading } from '@app/shared/store/actions'; import { ROUTES } from '@app/shared/constants'; import store from '../../../../index'; import { actions } from '.'; @@ -121,13 +119,17 @@ export function* sendTransactionSaga(action: ReturnType): Generator { try { - const asset: Asset = (yield call(getAssetInfo, action.payload) as unknown) as Asset; + yield put(setIsLoading(true)); + const assets = (yield call(getAssetsInfo, action.payload) as unknown) as Asset[]; - yield put(actions.getAssetInfo.success(asset)); + yield put(actions.getAssetInfo.success(assets)); + yield put(setIsLoading(false)); } catch (e) { + yield put(setIsLoading(false)); yield put(actions.getAssetInfo.failure(e)); } } + export function* getAssetListSaga(action: ReturnType): Generator { try { const assets: Asset[] = (yield call(getAssetList, action.payload) as unknown) as Asset[]; @@ -148,8 +150,8 @@ function* walletSaga() { yield takeLatest(actions.validateSendAddress.request, validateSendAddress); yield takeLatest(actions.validateAmount.request, validateAmount); yield takeLatest(actions.sendTransaction.request, sendTransactionSaga); - yield takeEvery(actions.getAssetInfo.request, getAssetInfoSaga); - yield takeEvery(actions.getAssetList.request, getAssetListSaga); + yield takeLatest(actions.getAssetInfo.request, getAssetInfoSaga); + yield takeLatest(actions.getAssetList.request, getAssetListSaga); } export default walletSaga; diff --git a/src/app/core/WasmWallet.ts b/src/app/core/WasmWallet.ts index ba99dfa..d5facb9 100644 --- a/src/app/core/WasmWallet.ts +++ b/src/app/core/WasmWallet.ts @@ -333,7 +333,7 @@ export default class WasmWallet { this.emit(BackgroundEvent.UNLOCK_WALLET, false); if (!this.wallet) { - this.wallet = new WasmWalletClient(PATH_DB, pass, config.path_node); + this.wallet = new WasmWalletClient(PATH_DB, pass, config.path_node, MyModule.Network.mainnet); } const responseHandler = (response) => { @@ -514,7 +514,7 @@ export default class WasmWallet { WasmWalletClient.CreateWallet(seed, PATH_DB, password); if (!this.wallet) { - this.wallet = new WasmWalletClient(PATH_DB, password, config.path_node); + this.wallet = new WasmWalletClient(PATH_DB, password, config.path_node, MyModule.Network.mainnet); } await this.fastSync(); diff --git a/src/app/core/api.ts b/src/app/core/api.ts index 280dfc4..a087de1 100644 --- a/src/app/core/api.ts +++ b/src/app/core/api.ts @@ -306,8 +306,8 @@ export function verifyPaymentProof(payment_proof: string) { return postMessage(RPCMethod.VerifyPaymentProof, { payment_proof }); } -export function getAssetInfo(asset_id: number) { - return postMessage(RPCMethod.GetAssetInfo, { asset_id }); +export async function getAssetsInfo(asset_ids: number[]) { + return Promise.all(asset_ids.map((asset_id) => postMessage(RPCMethod.GetAssetInfo, { asset_id }))); } export function getAssetList({ refresh }: { refresh: boolean }) { return postMessage(RPCMethod.AssetsList, { refresh }); diff --git a/src/app/shared/interface/ConfigInterface.ts b/src/app/shared/interface/ConfigInterface.ts index e274f58..a3d5181 100644 --- a/src/app/shared/interface/ConfigInterface.ts +++ b/src/app/shared/interface/ConfigInterface.ts @@ -6,6 +6,7 @@ export interface Configuration { theme: string; explorer_url_confidential_id: string; dex_url: string; + network: string; } export interface ConfigurationObject { diff --git a/src/app/shared/interface/SharedStateType.ts b/src/app/shared/interface/SharedStateType.ts index fbeb48c..c02ff5b 100644 --- a/src/app/shared/interface/SharedStateType.ts +++ b/src/app/shared/interface/SharedStateType.ts @@ -4,4 +4,5 @@ export interface SharedStateType { isBalanceHidden: boolean; isLocked: boolean; isAssetSync: boolean; + isLoading: boolean; } diff --git a/src/app/shared/store/actions.tsx b/src/app/shared/store/actions.tsx index bc34254..8942ed3 100755 --- a/src/app/shared/store/actions.tsx +++ b/src/app/shared/store/actions.tsx @@ -8,3 +8,5 @@ export const unlockWallet = createAction(SharedActionTypes.UNLOCK_WALLET)(); export const hideBalances = createAction(SharedActionTypes.HIDE_BALANCE)(); export const setAssetSync = createAction(SharedActionTypes.SYNC_ASSET)(); export const unsetAssetSync = createAction(SharedActionTypes.UNSET_SYNC_ASSET)(); + +export const setIsLoading = createAction(SharedActionTypes.SET_IS_LOADING)(); diff --git a/src/app/shared/store/constants.tsx b/src/app/shared/store/constants.tsx index 599c64b..49ca1ce 100755 --- a/src/app/shared/store/constants.tsx +++ b/src/app/shared/store/constants.tsx @@ -6,4 +6,5 @@ export enum SharedActionTypes { UNLOCK_WALLET = '@@SHARED/UNLOCK_WALLET', SYNC_ASSET = '@@SHARED/SYNC_ASSET', UNSET_SYNC_ASSET = '@@SHARED/UNSET_SYNC_ASSET', + SET_IS_LOADING = '@@SHARED/SET_IS_LOADING', } diff --git a/src/app/shared/store/reducer.tsx b/src/app/shared/store/reducer.tsx index fd94515..477c894 100644 --- a/src/app/shared/store/reducer.tsx +++ b/src/app/shared/store/reducer.tsx @@ -12,6 +12,7 @@ const initialState: SharedStateType = { isBalanceHidden: !!localStorage.getItem('isBalanceHidden') ?? false, isLocked: !!localStorage.getItem('locked') ?? false, isAssetSync: !!localStorage.getItem('asset_sync') ?? false, + isLoading: false, }; const reducer = createReducer(initialState) @@ -44,6 +45,9 @@ const reducer = createReducer(initialState) .handleAction(actions.unsetAssetSync, (state) => produce(state, (nexState) => { nexState.isAssetSync = false; localStorage.removeItem('asset_sync'); + })) + .handleAction(actions.setIsLoading, (state, action) => produce(state, (nexState) => { + nexState.isLoading = action.payload; })); export { reducer as SharedReducer }; diff --git a/src/app/shared/store/selectors.tsx b/src/app/shared/store/selectors.tsx index 871314d..02b5e6d 100644 --- a/src/app/shared/store/selectors.tsx +++ b/src/app/shared/store/selectors.tsx @@ -9,3 +9,4 @@ export const selectErrorMessage = () => createSelector(selectShared, (state) => export const selectIsBalanceHidden = () => createSelector(selectShared, (state) => state.isBalanceHidden); export const selectIsLocked = () => createSelector(selectShared, (state) => state.isLocked); export const selectAssetSync = () => createSelector(selectShared, (state) => state.isAssetSync); +export const selectIsLoading = () => createSelector(selectShared, (state) => state.isLoading); diff --git a/yarn.lock b/yarn.lock index c507e72..607dea4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2206,10 +2206,10 @@ base@^0.11.1: mixin-deep "^1.2.0" pascalcase "^0.1.1" -beam-wasm-client@7.3.14073: - version "7.3.14073" - resolved "https://registry.yarnpkg.com/beam-wasm-client/-/beam-wasm-client-7.3.14073.tgz#b1c48f40d009ef0b30ded4ddb5e3cbdcce46d650" - integrity sha512-uWJm1aF9hssRdBYAD+s1geGRLdInkyn5SWZEX3jnXrB7NWJWmE4iYTh2aR5nwQpxSi8SpKU9GYA+J7CHiSyrvA== +beam-wasm-client@7.3.13743: + version "7.3.13743" + resolved "https://registry.yarnpkg.com/beam-wasm-client/-/beam-wasm-client-7.3.13743.tgz#cfe25409784bae6ed8c340cc5ebe3e148cf9a140" + integrity sha512-4ec6PVdQFfLbCpmHEX3hcf6g65oCZIHykMEMz4YRRz4LqZtfqELmFGSHZ2vHkeIVUZFJg0vjO9aWfPnaU34zZQ== big.js@^5.2.2: version "5.2.2"