From 9a8f0ebad2a3ff1d2d6a153881a870d4099c563b Mon Sep 17 00:00:00 2001 From: "razvan.tomegea" Date: Fri, 11 Oct 2024 16:37:39 +0300 Subject: [PATCH 1/4] Allow only tokens and collections with prefix to be registered --- CHANGELOG.md | 2 ++ .../helpers/getRegisterTokenTransaction.ts | 2 +- .../hooks/useRegisterTokenOptions.ts | 24 +++++++++++-------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0785bd..398e2a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/src/pages/RegisterToken/helpers/getRegisterTokenTransaction.ts b/src/pages/RegisterToken/helpers/getRegisterTokenTransaction.ts index c4a38d2..ff2998a 100644 --- a/src/pages/RegisterToken/helpers/getRegisterTokenTransaction.ts +++ b/src/pages/RegisterToken/helpers/getRegisterTokenTransaction.ts @@ -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 = [ diff --git a/src/pages/RegisterToken/hooks/useRegisterTokenOptions.ts b/src/pages/RegisterToken/hooks/useRegisterTokenOptions.ts index 31240f5..3c6529a 100644 --- a/src/pages/RegisterToken/hooks/useRegisterTokenOptions.ts +++ b/src/pages/RegisterToken/hooks/useRegisterTokenOptions.ts @@ -13,22 +13,26 @@ export const useRegisterTokenOptions = (sendType: SendTypeEnum) => { ] = useLazyGetCollectionsQuery(); const getTokenOptionsByType = (type: SendTypeEnum): TokenOptionType[] => { + let options: TokenOptionType[] = []; + if (type === SendTypeEnum.nft) { - return ( + options = collections?.map((token) => ({ value: token.ticker, label: token.name - })) ?? [] - ); + })) ?? []; + } else { + // Remove EGLD + tokens.shift(); + + options = tokens.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) => From 08a6bc5e0c24e5bbb1a60d5042cf6753b63be8a1 Mon Sep 17 00:00:00 2001 From: "razvan.tomegea" Date: Mon, 14 Oct 2024 14:17:40 +0300 Subject: [PATCH 2/4] Fixed FaucetScreen.tsx --- package.json | 3 ++- src/pages/Faucet/components/FaucetScreen/FaucetScreen.tsx | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index db41062..fae3e53 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,8 @@ "copy:sovereign-config": "cp ./src/config/config.sovereign.ts ./src/config/index.ts", "test:pptr-headless": "npx @puppeteer/browsers install chrome-headless-shell@125.0.6420.0 && 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%", diff --git a/src/pages/Faucet/components/FaucetScreen/FaucetScreen.tsx b/src/pages/Faucet/components/FaucetScreen/FaucetScreen.tsx index e1cb62f..1629e31 100644 --- a/src/pages/Faucet/components/FaucetScreen/FaucetScreen.tsx +++ b/src/pages/Faucet/components/FaucetScreen/FaucetScreen.tsx @@ -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; @@ -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) => { From 2002c33e6c605381e867d754f77e991064ccd203 Mon Sep 17 00:00:00 2001 From: "razvan.tomegea" Date: Mon, 14 Oct 2024 15:46:29 +0300 Subject: [PATCH 3/4] Refactor --- src/hooks/tokens/useTokenOptions.ts | 22 ++++++++----------- .../hooks/useRegisterTokenOptions.ts | 22 +++++++++---------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/hooks/tokens/useTokenOptions.ts b/src/hooks/tokens/useTokenOptions.ts index 0762a59..d1a9aa3 100644 --- a/src/hooks/tokens/useTokenOptions.ts +++ b/src/hooks/tokens/useTokenOptions.ts @@ -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) => @@ -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, diff --git a/src/pages/RegisterToken/hooks/useRegisterTokenOptions.ts b/src/pages/RegisterToken/hooks/useRegisterTokenOptions.ts index 3c6529a..c172724 100644 --- a/src/pages/RegisterToken/hooks/useRegisterTokenOptions.ts +++ b/src/pages/RegisterToken/hooks/useRegisterTokenOptions.ts @@ -3,6 +3,7 @@ import { useGetTokensWithEgld } from 'hooks'; import { useGetAccountInfo } from 'lib'; import { useLazyGetCollectionsQuery } from 'redux/endpoints'; import { SendTypeEnum, TokenOptionType } from 'types'; +import { getEgldLabel } from '../../../lib'; export const useRegisterTokenOptions = (sendType: SendTypeEnum) => { const { address, websocketEvent } = useGetAccountInfo(); @@ -11,6 +12,7 @@ export const useRegisterTokenOptions = (sendType: SendTypeEnum) => { fetchCollections, { data: collections, isLoading: isLoadingCollections } ] = useLazyGetCollectionsQuery(); + const egldLabel = getEgldLabel(); const getTokenOptionsByType = (type: SendTypeEnum): TokenOptionType[] => { let options: TokenOptionType[] = []; @@ -22,13 +24,12 @@ export const useRegisterTokenOptions = (sendType: SendTypeEnum) => { label: token.name })) ?? []; } else { - // Remove EGLD - tokens.shift(); - - options = tokens.map((token) => ({ - value: token.identifier, - label: token.name - })); + options = tokens + .filter((token) => token.identifier !== egldLabel) + .map((token) => ({ + value: token.identifier, + label: token.name + })); } // Show only tokens/collections with a prefix (e.g. sov-FNG-123456) @@ -47,10 +48,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, From aea951c9e073bb79871162a5e3f61fbc30651c5a Mon Sep 17 00:00:00 2001 From: "razvan.tomegea" Date: Mon, 14 Oct 2024 15:50:59 +0300 Subject: [PATCH 4/4] Refactor --- src/pages/RegisterToken/hooks/useRegisterTokenOptions.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/RegisterToken/hooks/useRegisterTokenOptions.ts b/src/pages/RegisterToken/hooks/useRegisterTokenOptions.ts index c172724..7e2038d 100644 --- a/src/pages/RegisterToken/hooks/useRegisterTokenOptions.ts +++ b/src/pages/RegisterToken/hooks/useRegisterTokenOptions.ts @@ -1,9 +1,8 @@ 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'; -import { getEgldLabel } from '../../../lib'; export const useRegisterTokenOptions = (sendType: SendTypeEnum) => { const { address, websocketEvent } = useGetAccountInfo();