Skip to content

Commit

Permalink
[Issue-931]: Update showing minimum active value on mobile app
Browse files Browse the repository at this point in the history
  • Loading branch information
dominhquang committed Aug 21, 2023
1 parent 4421003 commit 41cdeb5
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 20 deletions.
5 changes: 4 additions & 1 deletion src/screens/Home/Browser/BrowserTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ const Component = ({ tabId, onOpenBrowserTabs, connectionTrigger }: Props, ref:
return false;
}
const urlParsed = new urlParse(url);

if (url.startsWith('wc:')) {
if (urlParsed.query.startsWith('?requestId')) {
return false;
Expand All @@ -442,6 +441,10 @@ const Component = ({ tabId, onOpenBrowserTabs, connectionTrigger }: Props, ref:
return false;
}

if (urlParsed.href.includes('wc?requestId')) {
return false;
}

if (urlParsed.href.startsWith('itms-appss://')) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Home/History/Detail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function HistoryDetailModal({

if (link) {
return (
<View style={{ alignSelf: 'stretch', marginBottom: 16 }}>
<View style={{ alignSelf: 'stretch' }}>
<Button icon={<Icon phosphorIcon={ArrowSquareUpRight} weight={'fill'} />} onPress={openBlockExplorer(link)}>
{i18n.common.viewOnExplorer}
</Button>
Expand Down
5 changes: 3 additions & 2 deletions src/screens/Home/History/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { TxTypeNameMap } from 'screens/Home/History/shared';
import i18n from 'utils/i18n/i18n';
import { FlatListScreen } from 'components/FlatListScreen';
import { FontMedium } from 'styles/sharedStyles';
import { ListRenderItemInfo, View } from 'react-native';
import { Keyboard, ListRenderItemInfo, View } from 'react-native';
import { SectionListData } from 'react-native/Libraries/Lists/SectionList';
import Typography from '../../../components/design-system-ui/typography';
import { useSubWalletTheme } from 'hooks/useSubWalletTheme';
Expand Down Expand Up @@ -320,8 +320,9 @@ function History({

const onOpenDetail = useCallback((item: TransactionHistoryDisplayItem) => {
return () => {
Keyboard.dismiss();
setSelectedItem(item);
setDetailModalVisible(true);
setTimeout(() => setDetailModalVisible(true), 200);
};
}, []);

Expand Down
80 changes: 64 additions & 16 deletions src/screens/Transaction/Stake/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import useFetchChainState from 'hooks/screen/useFetchChainState';
import i18n from 'utils/i18n/i18n';
import { ModalRef } from 'types/modalRef';
import { AccountSelector } from 'components/Modal/common/AccountSelector';
import { BN, BN_ZERO } from '@polkadot/util';
import { isSameAddress } from '@subwallet/extension-base/utils';

export const Stake = ({
route: {
Expand Down Expand Up @@ -123,7 +125,6 @@ export const Stake = ({
value: currentValue,
} = formState.data;

console.log('asset', asset);
const chainState = useFetchChainState(chain);
const chainStakingMetadata = useGetChainStakingMetadata(chain);
const nominatorMetadataList = useGetNominatorInfo(chain, currentStakingType as StakingType, from);
Expand Down Expand Up @@ -170,6 +171,28 @@ export const Stake = ({
return '0';
}, [assetRegistry, asset]);

const getSelectedValidators = useCallback(
(nominations: string[]) => {
const validatorList = validatorInfoMap[chain];

if (!validatorList) {
return [];
}

const result: ValidatorInfo[] = [];

validatorList.forEach(validator => {
if (nominations.some(nomination => isSameAddress(nomination, validator.address))) {
// remember the format of the address
result.push(validator);
}
});

return result;
},
[chain, validatorInfoMap],
);

const maxValue = useMemo(() => {
const balance = new BigN(nativeTokenBalance.value);
const ed = new BigN(existentialDeposit);
Expand Down Expand Up @@ -263,13 +286,44 @@ export const Stake = ({
return undefined;
}, [nominationPoolInfoMap, chain, currentPool]);

const minStake = useMemo(
() =>
(currentStakingType === StakingType.POOLED
? chainStakingMetadata?.minJoinNominationPool
: chainStakingMetadata?.minStake) || '0',
[chainStakingMetadata?.minJoinNominationPool, chainStakingMetadata?.minStake, currentStakingType],
);
const getValidatorMinStake = useCallback((validatorInfos: ValidatorInfo[]) => {
let minStake = BN_ZERO;

validatorInfos.forEach(validatorInfo => {
const bnMinBond = new BN(validatorInfo?.minBond);

if (bnMinBond.gt(minStake)) {
minStake = bnMinBond;
}
});

return minStake.toString();
}, []);

const chainMinStake = useMemo(() => {
return currentStakingType === StakingType.NOMINATED
? chainStakingMetadata?.minStake || '0'
: chainStakingMetadata?.minJoinNominationPool || '0';
}, [chainStakingMetadata?.minJoinNominationPool, chainStakingMetadata?.minStake, currentStakingType]);

const minStake = useMemo(() => {
if (currentStakingType === StakingType.NOMINATED) {
const validatorInfos = getSelectedValidators(parseNominations(currentValidator));
const validatorMinStake = getValidatorMinStake(validatorInfos);

const nominatedMinStake = BN.max(new BN(validatorMinStake), new BN(chainStakingMetadata?.minStake || '0'));
return nominatedMinStake.toString();
}

return chainStakingMetadata?.minJoinNominationPool || '0';
}, [
chainStakingMetadata?.minJoinNominationPool,
chainStakingMetadata?.minStake,
currentStakingType,
currentValidator,
getSelectedValidators,
getValidatorMinStake,
]);

const getMetaInfo = useCallback(() => {
if (chainStakingMetadata) {
Expand Down Expand Up @@ -427,13 +481,7 @@ export const Stake = ({
defaultValue={asset}
acceptDefaultValue={true}
renderSelected={() => (
<TokenSelectField
logoKey={symbol.toLowerCase()}
subLogoKey={chain}
value={symbol}
showIcon
outerStyle={stakingChain !== ALL_KEY || !from || loading}
/>
<TokenSelectField logoKey={symbol.toLowerCase()} subLogoKey={chain} value={symbol} showIcon />
)}
/>

Expand Down Expand Up @@ -508,7 +556,7 @@ export const Stake = ({
modalVisible={detailNetworkModalVisible}
chainStakingMetadata={chainStakingMetadata}
stakingType={currentStakingType as StakingType}
minimumActive={{ decimals, value: minStake, symbol }}
minimumActive={{ decimals, value: chainMinStake, symbol }}
setVisible={setDetailNetworkModalVisible}
/>
)}
Expand Down

0 comments on commit 41cdeb5

Please sign in to comment.