Skip to content

Commit

Permalink
Added default token in list (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
arhtudormorar authored Jun 28, 2024
1 parent c565ef6 commit 8c33407
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
41 changes: 28 additions & 13 deletions src/hooks/tokens/useGetTokensWithEgld.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,47 @@
import { useEffect } from 'react';
import uniqBy from 'lodash/unionBy';
import { useGetAccountInfo, useGetNetworkConfig } from 'lib';
import { useLazyGetTokensQuery } from 'redux/endpoints';
import { TokenType } from 'types';

const defaultValues = {
owner: '',
minted: '',
burnt: '',
supply: '',
circulatingSupply: '',
canBurn: false,
canChangeOwner: false,
canFreeze: false,
canMint: false,
canPause: false,
canUpgrade: false,
canWipe: false,
isPaused: false,
transactions: 0,
accounts: 0
};

export const useGetTokensWithEgld = () => {
const { websocketEvent, address, account } = useGetAccountInfo();
const { network } = useGetNetworkConfig();
const [fetchTokens, { data: tokens, isLoading }] = useLazyGetTokensQuery();

const egldToken: TokenType = {
...defaultValues,
identifier: network.egldLabel,
name: network.egldLabel,
balance: account?.balance
};

useEffect(() => {
fetchTokens(address);
}, [address, websocketEvent]);

const usedTokens = [...(tokens ?? [])];

if (usedTokens.length > 0) {
const egldToken: TokenType = {
...usedTokens[0],
identifier: network.egldLabel,
name: network.egldLabel,
balance: account?.balance
};

usedTokens.unshift(egldToken);
}
const usedTokens = [egldToken, ...(tokens ?? [])];

return {
tokens: usedTokens,
tokens: uniqBy(usedTokens, 'identifier'),
isLoading
};
};
2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import basicSsl from '@vitejs/plugin-basic-ssl';
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import { nodePolyfills } from 'vite-plugin-node-polyfills';
import svgrPlugin from 'vite-plugin-svgr';
import tsconfigPaths from 'vite-tsconfig-paths';
import basicSsl from '@vitejs/plugin-basic-ssl';

export default defineConfig({
server: {
Expand Down

0 comments on commit 8c33407

Please sign in to comment.