Skip to content

Commit

Permalink
Merge pull request #969 from Koniverse/issue-931
Browse files Browse the repository at this point in the history
[Issue-931]: Update showing minimum active value on mobile app
  • Loading branch information
nguyenduythuc authored Aug 22, 2023
2 parents 032db54 + 41cdeb5 commit de9a91e
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 19 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
79 changes: 64 additions & 15 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 @@ -169,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 @@ -262,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 @@ -426,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 @@ -507,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 de9a91e

Please sign in to comment.