Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
razvantomegea committed Oct 14, 2024
1 parent 08a6bc5 commit 2002c33
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
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
22 changes: 11 additions & 11 deletions src/pages/RegisterToken/hooks/useRegisterTokenOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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[] = [];
Expand All @@ -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)
Expand All @@ -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,
Expand Down

0 comments on commit 2002c33

Please sign in to comment.