Skip to content

Commit

Permalink
Merge pull request #346 from BeamMW/release/mainnet
Browse files Browse the repository at this point in the history
Release/mainnet
  • Loading branch information
razoorka committed Jun 16, 2023
2 parents 49f54ba + 226e1ea commit c99f725
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 40 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion src/app/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ 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 = {
...development,
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 = {
Expand All @@ -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 = {
Expand All @@ -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 = {
Expand All @@ -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 = {
Expand Down
44 changes: 27 additions & 17 deletions src/app/containers/Wallet/containers/Wallet/Wallet.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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]);

Expand All @@ -65,6 +73,8 @@ const Wallet = () => {
return (
<Window title="Wallet" primary showHideButton>
<WalletActions />
{isLoading && <Loader />}

<Section title="Assets" showAllAction={assets.length > TXS_MAX ? navigateToAssets : undefined}>
<Assets data={assts} isBalanceHidden={isBalanceHidden} />
</Section>
Expand Down
2 changes: 1 addition & 1 deletion src/app/containers/Wallet/store/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const getAssetInfo = createAsyncAction(
WalletActionTypes.GET_ASSET_INFO,
WalletActionTypes.GET_ASSET_INFO_SUCCESS,
WalletActionTypes.GET_ASSET_INFO_FAILURE,
)<number, Asset, ErrorMessage>();
)<number[], Asset[], ErrorMessage>();

export const getAssetList = createAsyncAction(
WalletActionTypes.GET_ASSET_LIST,
Expand Down
6 changes: 4 additions & 2 deletions src/app/containers/Wallet/store/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<WalletStateType, Action>(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;
Expand Down
20 changes: 11 additions & 9 deletions src/app/containers/Wallet/store/saga.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import {
call, put, takeEvery, takeLatest,
} from 'redux-saga/effects';
import { call, put, takeLatest } from 'redux-saga/effects';
import {
getWalletStatus,
createAddress,
validateAddress,
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 '.';
Expand Down Expand Up @@ -121,13 +119,17 @@ export function* sendTransactionSaga(action: ReturnType<typeof actions.sendTrans

export function* getAssetInfoSaga(action: ReturnType<typeof actions.getAssetInfo.request>): 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<typeof actions.getAssetList.request>): Generator {
try {
const assets: Asset[] = (yield call(getAssetList, action.payload) as unknown) as Asset[];
Expand All @@ -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;
4 changes: 2 additions & 2 deletions src/app/core/WasmWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/app/core/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ export function verifyPaymentProof(payment_proof: string) {
return postMessage(RPCMethod.VerifyPaymentProof, { payment_proof });
}

export function getAssetInfo(asset_id: number) {
return postMessage<Asset>(RPCMethod.GetAssetInfo, { asset_id });
export async function getAssetsInfo(asset_ids: number[]) {
return Promise.all(asset_ids.map((asset_id) => postMessage<Asset>(RPCMethod.GetAssetInfo, { asset_id })));
}
export function getAssetList({ refresh }: { refresh: boolean }) {
return postMessage<Asset[]>(RPCMethod.AssetsList, { refresh });
Expand Down
1 change: 1 addition & 0 deletions src/app/shared/interface/ConfigInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface Configuration {
theme: string;
explorer_url_confidential_id: string;
dex_url: string;
network: string;
}

export interface ConfigurationObject {
Expand Down
1 change: 1 addition & 0 deletions src/app/shared/interface/SharedStateType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface SharedStateType {
isBalanceHidden: boolean;
isLocked: boolean;
isAssetSync: boolean;
isLoading: boolean;
}
2 changes: 2 additions & 0 deletions src/app/shared/store/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)<boolean>();
1 change: 1 addition & 0 deletions src/app/shared/store/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
4 changes: 4 additions & 0 deletions src/app/shared/store/reducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<SharedStateType, Action>(initialState)
Expand Down Expand Up @@ -44,6 +45,9 @@ const reducer = createReducer<SharedStateType, Action>(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 };
1 change: 1 addition & 0 deletions src/app/shared/store/selectors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2206,10 +2206,10 @@ base@^0.11.1:
mixin-deep "^1.2.0"
pascalcase "^0.1.1"

[email protected].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==
[email protected].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"
Expand Down

0 comments on commit c99f725

Please sign in to comment.