Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow only tokens and collections with prefix to be registered #57

Merged
merged 4 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- [Allow only tokens and collections with prefix to be registered](https://github.com/multiversx/mx-lite-wallet-dapp/pull/56)

## [[1.0.2](https://github.com/multiversx/mx-lite-wallet-dapp/pull/54)] - 2024-10-03

- [Fixed faucet is missing on sovereign when recpatcha key is missing](https://github.com/multiversx/mx-lite-wallet-dapp/pull/55)
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"copy:sovereign-config": "cp ./src/config/config.sovereign.ts ./src/config/index.ts",
"test:pptr-headless": "npx @puppeteer/browsers install [email protected] && jest --config=jest-puppeteer.config.js",
"test:pptr": "JEST_PPTR_RETRY_TIMES=0 HEADLESS=false jest --config=jest-puppeteer.config.js",
"test": "jest"
"test": "jest",
"preview": "vite preview"
},
"browserslist": [
">0.2%",
Expand Down
22 changes: 9 additions & 13 deletions src/hooks/tokens/useTokenOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ export const useTokenOptions = ({
);
}

if (skipAddEgld && tokens[0]?.identifier === egldLabel) {
tokens.shift();
}

return tokens.map((token) => ({
value: token.identifier,
label: token.name
}));
return tokens
.filter((token) => !skipAddEgld || token.identifier !== egldLabel)
.map((token) => ({
value: token.identifier,
label: token.name
}));
};

const getTokens = (type: SendTypeEnum) =>
Expand All @@ -49,11 +47,9 @@ export const useTokenOptions = ({
[nfts, tokens, sendType]
);

const allTokens = [...tokens, ...(nfts || [])];

if (skipAddEgld && allTokens[0]?.identifier === egldLabel) {
allTokens.shift();
}
const allTokens = [...tokens, ...(nfts || [])].filter(
(token) => !skipAddEgld || token.identifier !== egldLabel
);

return {
allTokens,
Expand Down
3 changes: 1 addition & 2 deletions src/pages/Faucet/components/FaucetScreen/FaucetScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { DataTestIdsEnum } from 'localConstants';
import { FaucetSettingsReturnType } from 'redux/endpoints';

const sitekey = import.meta.env.VITE_APP_GOOGLE_RECAPTCHA_KEY;
const isDisabled = process.env.NODE_ENV === 'production';

export interface FaucetScreenPropsType {
settings: FaucetSettingsReturnType;
Expand All @@ -18,7 +17,7 @@ export const FaucetScreen = ({
onRequestClick
}: FaucetScreenPropsType) => {
const [captcha, setCaptcha] = useState('');
const [requestDisabled, setRequestDisabled] = useState(isDisabled);
const [requestDisabled, setRequestDisabled] = useState(false);
const egldLabel = getEgldLabel();

const onRecaptchaChange = (value: string | null) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const getRegisterTokenTransaction = ({
'identifier' in token ? token.identifier : token.ticker;
const tokenType = TokenTypeMap[nft.type] || 0;
const tokenName = token.name;
const tokenTicker = token.ticker?.split('-')[0];
const tokenTicker = token.ticker?.split('-')[1];
const tokenDecimals = token.decimals || 0;

const args = [
Expand Down
33 changes: 18 additions & 15 deletions src/pages/RegisterToken/hooks/useRegisterTokenOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useMemo } from 'react';
import { useGetTokensWithEgld } from 'hooks';
import { useGetAccountInfo } from 'lib';
import { useGetAccountInfo, getEgldLabel } from 'lib';
import { useLazyGetCollectionsQuery } from 'redux/endpoints';
import { SendTypeEnum, TokenOptionType } from 'types';

Expand All @@ -11,24 +11,28 @@ export const useRegisterTokenOptions = (sendType: SendTypeEnum) => {
fetchCollections,
{ data: collections, isLoading: isLoadingCollections }
] = useLazyGetCollectionsQuery();
const egldLabel = getEgldLabel();

const getTokenOptionsByType = (type: SendTypeEnum): TokenOptionType[] => {
let options: TokenOptionType[] = [];

if (type === SendTypeEnum.nft) {
return (
options =
collections?.map((token) => ({
value: token.ticker,
label: token.name
})) ?? []
);
})) ?? [];
} else {
options = tokens
.filter((token) => token.identifier !== egldLabel)
.map((token) => ({
value: token.identifier,
label: token.name
}));
}

// Remove EGLD
tokens.shift();

return tokens.map((token) => ({
value: token.identifier,
label: token.name
}));
// Show only tokens/collections with a prefix (e.g. sov-FNG-123456)
return options.filter((token) => token.value.split('-').length > 2);
};

const getTokens = (type: SendTypeEnum) =>
Expand All @@ -43,10 +47,9 @@ export const useRegisterTokenOptions = (sendType: SendTypeEnum) => {
[collections, tokens, sendType]
);

const allTokens = [...tokens, ...(collections || [])];

// Remove EGLD
allTokens.shift();
const allTokens = [...tokens, ...(collections || [])].filter(
(token) => !('identifier' in token) || token.identifier !== egldLabel
);

return {
allTokens,
Expand Down
Loading