From 30a6c560560c33c3d30e8a58a584de337542e468 Mon Sep 17 00:00:00 2001 From: Ikemefuna Obioha Date: Thu, 25 Jul 2024 20:12:27 +0100 Subject: [PATCH 01/16] Removed send and request buttons --- .../wallet/components/overview/overview.js | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/modules/wallet/components/overview/overview.js b/src/modules/wallet/components/overview/overview.js index a6c9323345..fcf94e94d5 100644 --- a/src/modules/wallet/components/overview/overview.js +++ b/src/modules/wallet/components/overview/overview.js @@ -14,7 +14,6 @@ import WalletVisualWithAddress from '@wallet/components/walletVisualWithAddress' import DialogLink from 'src/theme/dialog/link'; import { useCurrentAccount } from '@account/hooks'; import { useLatestBlock } from '@block/hooks/queries/useLatestBlock'; -import { SecondaryButton, PrimaryButton } from '@theme/buttons'; import { useValidators } from '@pos/validator/hooks/queries'; import { selectSearchParamValue } from 'src/utils/searchParams'; import { useAuth } from '@auth/hooks/queries'; @@ -119,22 +118,6 @@ const Overview = ({ isWalletRoute, history }) => { /> -
-
-
- {!searchAddress && ( - - {t('Request')} - - )} -
-
- - {t('Send')} - -
-
-
From 6bb92e9ca79658e54cc16477a7f0e5e2e3c90cff Mon Sep 17 00:00:00 2001 From: Ikemefuna Obioha Date: Thu, 25 Jul 2024 20:13:32 +0100 Subject: [PATCH 02/16] Removed transaction and events tab --- .../AccountDetails/AccountOverview/index.js | 41 +------------- .../ExplorerLayout/explorerLayout.js | 56 ++----------------- 2 files changed, 8 insertions(+), 89 deletions(-) diff --git a/src/modules/account/components/AccountDetails/AccountOverview/index.js b/src/modules/account/components/AccountDetails/AccountOverview/index.js index 4f8f005bcb..34f008a6e6 100644 --- a/src/modules/account/components/AccountDetails/AccountOverview/index.js +++ b/src/modules/account/components/AccountDetails/AccountOverview/index.js @@ -1,49 +1,24 @@ -import React, { useState } from 'react'; -import { useTranslation } from 'react-i18next'; +import React from 'react'; import { useSelector } from 'react-redux'; import { useCurrentAccount } from '@account/hooks'; import Overview from '@wallet/components/overview/overviewManager'; -import Box from '@theme/box'; -import BoxHeader from '@theme/box/header'; -import BoxTabs from '@theme/tabs'; -import BoxContent from '@theme/box/content'; -import Transactions from '@transaction/components/Explorer'; -import TransactionEvents from '@transaction/components/TransactionEvents'; import { selectActiveToken, selectSettings, selectTransactions } from 'src/redux/selectors'; import SwippableInfoBanner from '@common/components/infoBanner/swippableInfoBanner'; import banners from './banners'; -import styles from './AccountOverview.css'; // eslint-disable-next-line max-statements export default function AccountOverview({ address: searchAddress }) { - const { t } = useTranslation(); const activeToken = useSelector(selectActiveToken); const { discreetMode } = useSelector(selectSettings); const { confirmed } = useSelector(selectTransactions); - const [activeTab, setActiveTab] = useState('transactions'); const [ { metadata: { address: currentAddress }, }, ] = useCurrentAccount(); - const tabs = { - tabs: [ - { - value: 'transactions', - name: t('Transactions'), - className: 'transactions', - }, - { - value: 'events', - name: t('Events'), - className: 'events', - }, - ], - active: activeTab, - onClick: ({ value }) => setActiveTab(value), - }; const accountAddress = searchAddress ?? currentAddress; + console.log({ accountAddress }); return (
@@ -54,18 +29,6 @@ export default function AccountOverview({ address: searchAddress }) { discreetMode={discreetMode} transactions={confirmed} /> - - - - - - {activeTab === 'transactions' ? ( - - ) : ( - - )} - -
); } diff --git a/src/modules/wallet/components/ExplorerLayout/explorerLayout.js b/src/modules/wallet/components/ExplorerLayout/explorerLayout.js index 98ff5d06de..711853fe1a 100644 --- a/src/modules/wallet/components/ExplorerLayout/explorerLayout.js +++ b/src/modules/wallet/components/ExplorerLayout/explorerLayout.js @@ -1,55 +1,11 @@ /* istanbul ignore file */ -import React, { useState } from 'react'; -import { useTranslation } from 'react-i18next'; -import Box from 'src/theme/box'; -import BoxTabs from 'src/theme/tabs'; -import BoxHeader from 'src/theme/box/header'; -import BoxContent from 'src/theme/box/content'; -import { selectSearchParamValue } from 'src/utils/searchParams'; -import Transactions from '@transaction/components/Explorer'; -import TransactionEvents from '@transaction/components/TransactionEvents'; +import React from 'react'; import Overview from '../overview/overviewManager'; -import styles from './explorerLayout.css'; -const ExplorerLayout = ({ history }) => { - const { t } = useTranslation(); - const address = selectSearchParamValue(history.location.search, 'address'); - const [activeTab, setActiveTab] = useState('transactions'); - - const tabs = { - tabs: [ - { - value: 'transactions', - name: t('Transactions'), - className: 'transactions', - }, - { - value: 'events', - name: t('Events'), - className: 'events', - }, - ], - active: activeTab, - onClick: ({ value }) => setActiveTab(value), - }; - - return ( -
- - - - - - - {activeTab === 'transactions' ? ( - - ) : ( - - )} - - -
- ); -}; +const ExplorerLayout = () => ( +
+ +
+); export default ExplorerLayout; From 1a55f5e3080e1e2ab32a5c48ecfbbfe135919a07 Mon Sep 17 00:00:00 2001 From: Ikemefuna Obioha Date: Tue, 30 Jul 2024 14:18:56 +0100 Subject: [PATCH 03/16] Add final balance and download history button --- src/const/queries.js | 1 + src/locales/en/common.json | 1 + .../NetworkSwitcherDropdown.js | 3 +- .../token/fungible/hooks/queries/index.js | 1 + .../fungible/hooks/queries/useLiskLegacy.js | 25 ++++++++++++++ .../wallet/components/TokenCard/TokenCard.js | 9 +++-- .../wallet/components/overview/overview.css | 5 +-- .../wallet/components/overview/overview.js | 34 ++++++++++++++++--- 8 files changed, 67 insertions(+), 12 deletions(-) create mode 100644 src/modules/token/fungible/hooks/queries/useLiskLegacy.js diff --git a/src/const/queries.js b/src/const/queries.js index ab2ef58b25..d0cd200d81 100644 --- a/src/const/queries.js +++ b/src/const/queries.js @@ -6,6 +6,7 @@ export const TOKENS_BALANCE = 'GET_TOKENS_BALANCE'; export const TOKENS_SUPPORTED = 'GET_TOKENS_SUPPORTED'; export const TOKEN_BALANCES_TOP = 'GET_TOKEN_BALANCES_TOP'; export const TOKENS_ACCOUNT_EXISTS = 'GET_TOKENS_ACCOUNT_EXISTS'; +export const LISK_LEGACY = 'GET_LISK_LEGACY'; export const PEERS = 'GET_PEERS'; export const VALIDATORS = 'GET_VALIDATORS'; export const STAKES_SENT = 'GET_STAKES_SENT'; diff --git a/src/locales/en/common.json b/src/locales/en/common.json index de08805c96..c89924bca4 100644 --- a/src/locales/en/common.json +++ b/src/locales/en/common.json @@ -186,6 +186,7 @@ "Done": "Done", "Don’t have a Lisk account yet?": "Don’t have a Lisk account yet?", "Download": "Download", + "Download account history": "Download account history", "Download completed": "Download completed", "Duplicate public keys detected.": "Duplicate public keys detected.", "Edit": "Edit", diff --git a/src/modules/network/components/networkSwitcherDropdown/NetworkSwitcherDropdown.js b/src/modules/network/components/networkSwitcherDropdown/NetworkSwitcherDropdown.js index c1da02a9f9..66ee28855f 100644 --- a/src/modules/network/components/networkSwitcherDropdown/NetworkSwitcherDropdown.js +++ b/src/modules/network/components/networkSwitcherDropdown/NetworkSwitcherDropdown.js @@ -16,7 +16,6 @@ function NetworkSwitcherDropdown({ noLabel, onNetworkSwitchSuccess }) { } = useSettings('mainChainNetwork'); const networksWithCustomNetworks = [...Object.values(networks)]; - const networkStatus = { isSuccess: true, isFetching: false, @@ -25,7 +24,7 @@ function NetworkSwitcherDropdown({ noLabel, onNetworkSwitchSuccess }) { const handleChangeNetwork = (network) => { setSelectedNetwork(network); setValue(network); - } + }; useEffect(() => { const isSuccess = networkStatus.isSuccess && !networkStatus.isFetching; diff --git a/src/modules/token/fungible/hooks/queries/index.js b/src/modules/token/fungible/hooks/queries/index.js index a321027d02..3fafff925c 100644 --- a/src/modules/token/fungible/hooks/queries/index.js +++ b/src/modules/token/fungible/hooks/queries/index.js @@ -8,3 +8,4 @@ export * from './useGetMinimumMessageFee'; export * from './useAppsMetaTokens'; export * from './useNetworkSupportedTokens'; export * from './useValidateFeeBalance'; +export * from './useLiskLegacy'; diff --git a/src/modules/token/fungible/hooks/queries/useLiskLegacy.js b/src/modules/token/fungible/hooks/queries/useLiskLegacy.js new file mode 100644 index 0000000000..c44b0492dd --- /dev/null +++ b/src/modules/token/fungible/hooks/queries/useLiskLegacy.js @@ -0,0 +1,25 @@ +import { useCurrentAccount } from 'src/modules/account/hooks'; +import { useCustomQuery } from 'src/modules/common/hooks'; +import { LISK_LEGACY } from 'src/const/queries'; +import defaultClient from 'src/utils/api/client'; + +export const useLiskLegacy = ({ + config: customConfig = {}, + options, + client = defaultClient, +} = {}) => { + const [currentAccount] = useCurrentAccount(); + const address = customConfig.params?.address || currentAccount.metadata?.address; + const config = { + url: `/accounts/${address}.json`, + method: 'get', + ...customConfig, + }; + + return useCustomQuery({ + keys: [LISK_LEGACY], + config, + options, + client, + }); +}; diff --git a/src/modules/wallet/components/TokenCard/TokenCard.js b/src/modules/wallet/components/TokenCard/TokenCard.js index 4641879ffb..00a20cac43 100644 --- a/src/modules/wallet/components/TokenCard/TokenCard.js +++ b/src/modules/wallet/components/TokenCard/TokenCard.js @@ -27,7 +27,12 @@ const TokenCard = ({ token, searchAddress }) => { {symbol}
- + {symbol === 'LSK' && ( { to={`${routes.sentStakes.path}/?modal=lockedBalance`} > - + )}
diff --git a/src/modules/wallet/components/overview/overview.css b/src/modules/wallet/components/overview/overview.css index fcc4cac396..49b1040fbc 100644 --- a/src/modules/wallet/components/overview/overview.css +++ b/src/modules/wallet/components/overview/overview.css @@ -54,11 +54,8 @@ } & .actionButtons { + display: flex; justify-content: flex-end; - - & button { - width: 100%; - } } } diff --git a/src/modules/wallet/components/overview/overview.js b/src/modules/wallet/components/overview/overview.js index fcf94e94d5..f867581c5b 100644 --- a/src/modules/wallet/components/overview/overview.js +++ b/src/modules/wallet/components/overview/overview.js @@ -4,7 +4,7 @@ import { useSelector } from 'react-redux'; import { Link } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import grid from 'flexboxgrid/dist/flexboxgrid.css'; -import { useTokenBalances } from '@token/fungible/hooks/queries'; +import { useTokenBalances, useLiskLegacy } from '@token/fungible/hooks/queries'; import TokenCard from '@wallet/components/TokenCard'; import TokenCarousel from '@wallet/components/TokenCarousel/TokenCarousel'; import { selectActiveTokenAccount } from 'src/redux/selectors'; @@ -14,10 +14,13 @@ import WalletVisualWithAddress from '@wallet/components/walletVisualWithAddress' import DialogLink from 'src/theme/dialog/link'; import { useCurrentAccount } from '@account/hooks'; import { useLatestBlock } from '@block/hooks/queries/useLatestBlock'; +import { PrimaryButton } from '@theme/buttons'; import { useValidators } from '@pos/validator/hooks/queries'; import { selectSearchParamValue } from 'src/utils/searchParams'; import { useAuth } from '@auth/hooks/queries'; +import { Client } from 'src/utils/api/client'; import routes from 'src/routes/routes'; +import { downloadJSON } from 'src/modules/transaction/utils'; import styles from './overview.css'; // 6: blocks per minute, 60: minutes, 24: hours @@ -53,12 +56,24 @@ const Overview = ({ isWalletRoute, history }) => { const daysLeft = Math.ceil((1000 - currentHeight) / numOfBlockPerDay); const wallet = useSelector(selectActiveTokenAccount); + const legacyClient = new Client(); + legacyClient.create({ http: 'https://legacy.lisk.com/' }); + const { - data: tokenBalances, + data: liskLegacy, isLoading, error, refetch, - } = useTokenBalances({ config: { params: { address } } }); + } = useLiskLegacy({ config: { params: { address } }, client: legacyClient }); + const tokenLegacyBalance = liskLegacy + ? { + ...liskLegacy.token, + symbol: 'LSK', + logo: { + svg: 'https://raw.githubusercontent.com/LiskHQ/app-registry/main/testnet/Lisk/images/tokens/lisk.svg', + }, + } + : {}; const { data: myTokenBalances } = useTokenBalances(); const hasTokenWithBalance = myTokenBalances?.data?.some( (tokenBalance) => BigInt(tokenBalance?.availableBalance || 0) > BigInt(0) @@ -100,6 +115,10 @@ const Overview = ({ isWalletRoute, history }) => { useEffect(showWarning, [isWalletRoute, host, address, pomHeights]); + const downloadAccountHistory = () => { + downloadJSON(liskLegacy, `${accountName}_account_history`); + }; + return (
{ />
+
+ + {t('Download account history')} + +
@@ -129,7 +155,7 @@ const Overview = ({ isWalletRoute, history }) => { )}
Date: Tue, 30 Jul 2024 14:58:43 +0100 Subject: [PATCH 04/16] Code cleanup --- .../AccountDetails/AccountOverview/index.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/modules/account/components/AccountDetails/AccountOverview/index.js b/src/modules/account/components/AccountDetails/AccountOverview/index.js index 34f008a6e6..a08f6a7ad9 100644 --- a/src/modules/account/components/AccountDetails/AccountOverview/index.js +++ b/src/modules/account/components/AccountDetails/AccountOverview/index.js @@ -1,24 +1,15 @@ import React from 'react'; import { useSelector } from 'react-redux'; -import { useCurrentAccount } from '@account/hooks'; import Overview from '@wallet/components/overview/overviewManager'; import { selectActiveToken, selectSettings, selectTransactions } from 'src/redux/selectors'; import SwippableInfoBanner from '@common/components/infoBanner/swippableInfoBanner'; import banners from './banners'; // eslint-disable-next-line max-statements -export default function AccountOverview({ address: searchAddress }) { +export default function AccountOverview() { const activeToken = useSelector(selectActiveToken); const { discreetMode } = useSelector(selectSettings); const { confirmed } = useSelector(selectTransactions); - const [ - { - metadata: { address: currentAddress }, - }, - ] = useCurrentAccount(); - - const accountAddress = searchAddress ?? currentAddress; - console.log({ accountAddress }); return (
From e6df055ea23ab0489dd3b5ea2ae34d5c508df30f Mon Sep 17 00:00:00 2001 From: Ikemefuna Obioha Date: Tue, 30 Jul 2024 15:06:34 +0100 Subject: [PATCH 05/16] Fix failing test --- .../components/overview/overview.test.js | 52 +++++++------------ 1 file changed, 20 insertions(+), 32 deletions(-) diff --git a/src/modules/wallet/components/overview/overview.test.js b/src/modules/wallet/components/overview/overview.test.js index 84ff2a793f..f65e189155 100644 --- a/src/modules/wallet/components/overview/overview.test.js +++ b/src/modules/wallet/components/overview/overview.test.js @@ -2,12 +2,10 @@ import React from 'react'; import { MemoryRouter } from 'react-router'; import { render, screen } from '@testing-library/react'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; -import numeral from 'numeral'; import mockSavedAccounts from '@tests/fixtures/accounts'; -import { useTokenBalances } from '@token/fungible/hooks/queries'; +import { useTokenBalances, useLiskLegacy } from '@token/fungible/hooks/queries'; import { useValidators } from '@pos/validator/hooks/queries'; import { useAuth } from '@auth/hooks/queries'; -import { convertFromBaseDenom } from '@token/fungible/utils/helpers'; import { mockBlocks } from '@block/__fixtures__'; import { mockValidators } from '@pos/validator/__fixtures__'; @@ -59,6 +57,22 @@ describe('Overview', () => { isLoading: false, isSuccess: true, }); + useLiskLegacy.mockReturnValue({ + data: { + token: { + availableBalance: '1586739386', + lockedBalances: [ + { + module: 'pos', + amount: '1000000000000', + }, + ], + symbol: 'LSK', + }, + }, + isLoading: false, + isSuccess: true, + }); useAuth.mockReturnValue({ data: mockAuth }); useValidators.mockReturnValue({ data: mockValidators }); useBlocks.mockReturnValue({ data: mockBlocks }); @@ -73,40 +87,14 @@ describe('Overview', () => { ); - expect(screen.getByText('Request')).toBeTruthy(); - expect(screen.getByText('Send')).toBeTruthy(); expect(screen.getByText('Tokens')).toBeTruthy(); expect(screen.getByText(mockAuth.meta.address)).toBeTruthy(); expect(screen.getByText(mockedCurrentAccount.metadata.name)).toBeTruthy(); expect(screen.getByText('View all tokens')).toBeTruthy(); - expect(screen.getAllByTestId('token-card')).toHaveLength(mergedTokens.length); + expect(screen.getAllByTestId('token-card')).toHaveLength(1); - mergedTokens.forEach(({ symbol, availableBalance, lockedBalances }) => { - const lockedBalance = lockedBalances.reduce((total, { amount }) => +amount + total, 0); - - expect( - screen.queryByText( - `${numeral(convertFromBaseDenom(lockedBalance, mockAppsTokens.data[0])).format( - '0' - )} ${symbol.toUpperCase()}` - ) - ); - expect( - screen.queryByText( - `${numeral(convertFromBaseDenom(availableBalance, mockAppsTokens.data[0])).format( - '0,0.00' - )}` - ) - ); - expect( - screen.queryByText( - `${numeral( - convertFromBaseDenom(+availableBalance + lockedBalance, mockAppsTokens.data[0]) - ).format('0,0.00')}` - ) - ); - expect(screen.getByAltText(symbol)).toBeTruthy(); - }); + expect(screen.getByText('15.86739386 LSK')).toBeTruthy(); + expect(screen.getByText('10,000 LSK')).toBeTruthy(); }); }); From 41bbe2144d8cd82374d3017006dd6af5e2da597d Mon Sep 17 00:00:00 2001 From: Ikemefuna Obioha Date: Tue, 30 Jul 2024 15:19:02 +0100 Subject: [PATCH 06/16] Fix DeepScan issue --- .../wallet/components/overview/overview.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/modules/wallet/components/overview/overview.js b/src/modules/wallet/components/overview/overview.js index f867581c5b..47785baf8a 100644 --- a/src/modules/wallet/components/overview/overview.js +++ b/src/modules/wallet/components/overview/overview.js @@ -66,14 +66,16 @@ const Overview = ({ isWalletRoute, history }) => { refetch, } = useLiskLegacy({ config: { params: { address } }, client: legacyClient }); const tokenLegacyBalance = liskLegacy - ? { - ...liskLegacy.token, - symbol: 'LSK', - logo: { - svg: 'https://raw.githubusercontent.com/LiskHQ/app-registry/main/testnet/Lisk/images/tokens/lisk.svg', + ? [ + { + ...liskLegacy.token, + symbol: 'LSK', + logo: { + svg: 'https://raw.githubusercontent.com/LiskHQ/app-registry/main/testnet/Lisk/images/tokens/lisk.svg', + }, }, - } - : {}; + ] + : [{}]; const { data: myTokenBalances } = useTokenBalances(); const hasTokenWithBalance = myTokenBalances?.data?.some( (tokenBalance) => BigInt(tokenBalance?.availableBalance || 0) > BigInt(0) @@ -155,7 +157,7 @@ const Overview = ({ isWalletRoute, history }) => { )}
Date: Wed, 31 Jul 2024 13:25:26 +0100 Subject: [PATCH 07/16] PR review fixes --- .../manage/hooks/useApplicationManagement.js | 3 ++ .../NetworkSwitcherDropdown.js | 13 ++++++++ .../NetworkSwitcherDropdown.test.js | 14 +++++++++ .../components/TokenCarousel/TokenCarousel.js | 2 +- .../wallet/components/overview/overview.js | 30 ++++++++++++++----- 5 files changed, 53 insertions(+), 9 deletions(-) diff --git a/src/modules/blockchainApplication/manage/hooks/useApplicationManagement.js b/src/modules/blockchainApplication/manage/hooks/useApplicationManagement.js index c055fd6199..60d37befea 100644 --- a/src/modules/blockchainApplication/manage/hooks/useApplicationManagement.js +++ b/src/modules/blockchainApplication/manage/hooks/useApplicationManagement.js @@ -19,6 +19,8 @@ export function useApplicationManagement({ queryClient } = {}) { const { checkPinByChainId, pins } = usePinBlockchainApplication(); const applicationsObject = useSelector(selectApplications)[mainChainNetwork.name] || {}; + const networkApplications = useSelector(selectApplications) || {}; + const applications = useMemo(() => { const appsList = Object.values(applicationsObject).filter((app) => app?.status); // Sort apps list by pinned apps and terminated apps such that @@ -63,6 +65,7 @@ export function useApplicationManagement({ queryClient } = {}) { return { isLoading, applications, + networkApplications, setApplication, setApplications, getApplicationByChainId, diff --git a/src/modules/network/components/networkSwitcherDropdown/NetworkSwitcherDropdown.js b/src/modules/network/components/networkSwitcherDropdown/NetworkSwitcherDropdown.js index 66ee28855f..8cad77de52 100644 --- a/src/modules/network/components/networkSwitcherDropdown/NetworkSwitcherDropdown.js +++ b/src/modules/network/components/networkSwitcherDropdown/NetworkSwitcherDropdown.js @@ -4,6 +4,10 @@ import { useTranslation } from 'react-i18next'; import MenuSelect from '@wallet/components/MenuSelect'; import useSettings from '@settings/hooks/useSettings'; import NetworkMenuItem from '@network/components/networkSwitcherDropdown/networkMenuItem/NetworkMenuItem'; +import { + useApplicationManagement, + useCurrentApplication, +} from '@blockchainApplication/manage/hooks'; import networks from '../../configuration/networks'; import styles from './NetworkSwitcherDropdown.css'; @@ -15,15 +19,24 @@ function NetworkSwitcherDropdown({ noLabel, onNetworkSwitchSuccess }) { mainChainNetwork: { name: currentNetworkName }, } = useSettings('mainChainNetwork'); const networksWithCustomNetworks = [...Object.values(networks)]; + const { networkApplications } = useApplicationManagement(); + const [, setCurrentApplication] = useCurrentApplication(); const networkStatus = { isSuccess: true, isFetching: false, }; + const liskChains = { + mainnet: '00000000', + testnet: '01000000', + }; + const handleChangeNetwork = (network) => { + const selectedNetworkApplication = networkApplications[network.name][liskChains[network.name]]; setSelectedNetwork(network); setValue(network); + setCurrentApplication(selectedNetworkApplication); }; useEffect(() => { diff --git a/src/modules/network/components/networkSwitcherDropdown/NetworkSwitcherDropdown.test.js b/src/modules/network/components/networkSwitcherDropdown/NetworkSwitcherDropdown.test.js index a83456e3c3..b0e0bbf38b 100644 --- a/src/modules/network/components/networkSwitcherDropdown/NetworkSwitcherDropdown.test.js +++ b/src/modules/network/components/networkSwitcherDropdown/NetworkSwitcherDropdown.test.js @@ -3,6 +3,10 @@ import useSettings from '@settings/hooks/useSettings'; import { mockBlockchainAppMeta } from '@blockchainApplication/manage/__fixtures__'; import { rerenderWithRouterAndQueryClient } from 'src/utils/testHelpers'; import NetworkSwitcherDropdown from '@network/components/networkSwitcherDropdown/NetworkSwitcherDropdown'; +import { + useApplicationManagement, + useCurrentApplication, +} from '@blockchainApplication/manage/hooks'; import { mockNetworkStatus } from '../../__fixtures__'; import { useNetworkStatus } from '../../hooks/queries'; @@ -33,6 +37,16 @@ describe('NetworkSwitcherDropdown', () => { isFetched: true, refetch: jest.fn(), }); + useCurrentApplication.mockReturnValue([mockBlockchainAppMeta.data[0], jest.fn()]); + useApplicationManagement.mockReturnValue({ + networkApplications: [ + { + devnet: { + '04000000': mockBlockchainAppMeta.data[0], + }, + }, + ], + }); it('should render properly', () => { rerenderWithRouterAndQueryClient(NetworkSwitcherDropdown, props); diff --git a/src/modules/wallet/components/TokenCarousel/TokenCarousel.js b/src/modules/wallet/components/TokenCarousel/TokenCarousel.js index 21cefc6e74..07c31edd02 100644 --- a/src/modules/wallet/components/TokenCarousel/TokenCarousel.js +++ b/src/modules/wallet/components/TokenCarousel/TokenCarousel.js @@ -54,7 +54,7 @@ const Carousel = ({ renderItem: RenderItem, data = [], isLoading, error, ...rest return ; } - if (error) { + if (error && error.response.status !== 404) { return (

{error?.message || error}

diff --git a/src/modules/wallet/components/overview/overview.js b/src/modules/wallet/components/overview/overview.js index 47785baf8a..502dd92741 100644 --- a/src/modules/wallet/components/overview/overview.js +++ b/src/modules/wallet/components/overview/overview.js @@ -18,6 +18,8 @@ import { PrimaryButton } from '@theme/buttons'; import { useValidators } from '@pos/validator/hooks/queries'; import { selectSearchParamValue } from 'src/utils/searchParams'; import { useAuth } from '@auth/hooks/queries'; +import useSettings from 'src/modules/settings/hooks/useSettings'; +import networks from 'src/modules/network/configuration/networks'; import { Client } from 'src/utils/api/client'; import routes from 'src/routes/routes'; import { downloadJSON } from 'src/modules/transaction/utils'; @@ -41,6 +43,8 @@ const Overview = ({ isWalletRoute, history }) => { const searchAddress = selectSearchParamValue(history.location.search, 'address'); const { t } = useTranslation(); const [{ metadata: { address: currentAddress, name } = {} }] = useCurrentAccount(); + const { mainChainNetwork } = useSettings('mainChainNetwork'); + const isTestnet = mainChainNetwork.serviceUrl === networks.testnet.serviceUrl; const address = useMemo(() => searchAddress || currentAddress, [searchAddress, currentAddress]); const { data: validators } = useValidators({ config: { params: { address } } }); @@ -65,6 +69,14 @@ const Overview = ({ isWalletRoute, history }) => { error, refetch, } = useLiskLegacy({ config: { params: { address } }, client: legacyClient }); + const defaultLegacyBalance = { + availableBalance: '0', + lockedBalances: [{ module: 'pos', amount: '0' }], + symbol: 'LSK', + logo: { + svg: 'https://raw.githubusercontent.com/LiskHQ/app-registry/main/testnet/Lisk/images/tokens/lisk.svg', + }, + }; const tokenLegacyBalance = liskLegacy ? [ { @@ -75,7 +87,7 @@ const Overview = ({ isWalletRoute, history }) => { }, }, ] - : [{}]; + : [defaultLegacyBalance]; const { data: myTokenBalances } = useTokenBalances(); const hasTokenWithBalance = myTokenBalances?.data?.some( (tokenBalance) => BigInt(tokenBalance?.availableBalance || 0) > BigInt(0) @@ -139,13 +151,15 @@ const Overview = ({ isWalletRoute, history }) => { />
-
- - {t('Download account history')} - -
+ {!isTestnet && ( +
+ + {t('Download account history')} + +
+ )}
From de43895e14489ab54acc9547ba50abb65a2d58d2 Mon Sep 17 00:00:00 2001 From: Ikemefuna Obioha Date: Wed, 31 Jul 2024 16:05:16 +0100 Subject: [PATCH 08/16] Added fallback applications to fix incognito bug --- setup/react/app/ApplicationBootstrap.js | 6 + .../manage/const/liskApplications.js | 103 ++++++++++++++++++ .../manage/hooks/useApplicationManagement.js | 4 +- 3 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 src/modules/blockchainApplication/manage/const/liskApplications.js diff --git a/setup/react/app/ApplicationBootstrap.js b/setup/react/app/ApplicationBootstrap.js index c37249d76f..4b3f3d4136 100644 --- a/setup/react/app/ApplicationBootstrap.js +++ b/setup/react/app/ApplicationBootstrap.js @@ -2,9 +2,11 @@ /* eslint-disable max-statements */ import React, { createContext } from 'react'; import { useCurrentAccount } from 'src/modules/account/hooks'; +import { useCurrentApplication } from 'src/modules/blockchainApplication/manage/hooks'; import { useReduxStateModifier } from 'src/utils/useReduxStateModifier'; import { useLedgerDeviceListener } from '@libs/hardwareWallet/ledger/ledgerDeviceListener/useLedgerDeviceListener'; import { useRewardsClaimable } from 'src/modules/pos/reward/hooks/queries'; +import { liskMainnetApplication } from 'src/modules/blockchainApplication/manage/const/liskApplications'; export const ApplicationBootstrapContext = createContext({ hasNetworkError: false, @@ -17,6 +19,10 @@ export const ApplicationBootstrapContext = createContext({ const ApplicationBootstrap = ({ children }) => { const [currentAccount] = useCurrentAccount(); const accountAddress = currentAccount?.metadata?.address; + const [currentApplication, setCurrentApplication] = useCurrentApplication(); + if (!Object.keys(currentApplication).length) { + setCurrentApplication(liskMainnetApplication['00000000']); + } useLedgerDeviceListener(); useReduxStateModifier(); diff --git a/src/modules/blockchainApplication/manage/const/liskApplications.js b/src/modules/blockchainApplication/manage/const/liskApplications.js new file mode 100644 index 0000000000..f878fd0d57 --- /dev/null +++ b/src/modules/blockchainApplication/manage/const/liskApplications.js @@ -0,0 +1,103 @@ +export const liskMainnetApplication = { + '00000000': { + chainName: 'lisk_mainchain', + displayName: 'Lisk', + chainID: '00000000', + title: 'Lisk - Mainnet', + description: 'Metadata configuration for the Lisk blockchain (mainchain) in mainnet', + networkType: 'mainnet', + isDefault: true, + status: 'activated', + genesisURL: 'https://downloads.lisk.com/lisk/mainnet/genesis_block.json.tar.gz', + projectPage: 'https://lisk.com', + serviceURLs: [ + { + http: 'https://service.lisk.com', + ws: 'wss://service.lisk.com', + apiCertificatePublicKey: + '-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwAOGlgzeePs8O7FjSU9a\nUKQg4EYSJNgQqkwD/ITAJ6TzcXRCUK+N230NaFcQ8EFJw/8Al0r8mpjpOOEpPZDq\n+WljcCRkVHXZCJMvgDNcstzdrt1fKzsCrER2jB3hDUXt04xzzlk8ArJG0JeD/CmW\nAsQqL/S6v/GRVTuViHqzWm2eF2XrduUK8wIbQ1y+7HoVdgZDf5MpuvEXluVX4IeJ\nMyzbn9djdrDkHkcbml8dOHyLE6GOS5jKtXj+bKhyTVlSZFbexxKYiBqCpR6kMUnM\nVrURmWGT+jb7UhGkJiP7EpFB7MjAB+yXMiygd6lz67qjG6wFky1wB9NYGJ/50rrV\nDQIDAQAB\n-----END PUBLIC KEY-----', + }, + ], + logo: { + png: 'https://raw.githubusercontent.com/LiskHQ/app-registry/main/mainnet/Lisk/images/application/lisk.png', + svg: 'https://raw.githubusercontent.com/LiskHQ/app-registry/main/mainnet/Lisk/images/application/lisk.svg', + }, + explorers: [ + { + url: 'https://liskscan.com', + txnPage: 'https://liskscan.com/transactions', + }, + { + url: 'https://lisk.observer', + txnPage: 'https://lisk.observer/transactions', + }, + ], + appNodes: [ + { + url: 'https://mainnet.lisk.com', + apiCertificatePublicKey: + '-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqiQIDBSSlqKeWo0st2Hy\nJRbDzqYgcZfQvOpttr4kMbDjAYnz6XvZe3kOHcnMM2ePWrAS66SHTqdVbEEiu9Kf\njEQQkmk/Xv7XSMQ5kwidv+ANNDjTaC9GRnUHQ3pH77ZZY5msq0kEvmDvyMljU9kD\neqpugQn7jQVTG7te7PyXnZxvzMq8tgDILEwRnkF2hUF6jCH5X763aOT7X6yKUKY5\nZSUqmStKGPt1i34E5Pvb2AumsApkyqXfST/N/h8NV3UXRTBQ/fwAEvtOj3IMNNrw\nRUZIYAvwPFxTLXF0Dfj0fEiLFQzq+VPk3jsD9EbH1FotHXPtgA7brvG0uHfWKNsQ\nIQIDAQAB\n-----END PUBLIC KEY-----', + maintainer: 'Lightcurve GmbH', + }, + { + url: 'wss://mainnet.lisk.com', + apiCertificatePublicKey: + '-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqiQIDBSSlqKeWo0st2Hy\nJRbDzqYgcZfQvOpttr4kMbDjAYnz6XvZe3kOHcnMM2ePWrAS66SHTqdVbEEiu9Kf\njEQQkmk/Xv7XSMQ5kwidv+ANNDjTaC9GRnUHQ3pH77ZZY5msq0kEvmDvyMljU9kD\neqpugQn7jQVTG7te7PyXnZxvzMq8tgDILEwRnkF2hUF6jCH5X763aOT7X6yKUKY5\nZSUqmStKGPt1i34E5Pvb2AumsApkyqXfST/N/h8NV3UXRTBQ/fwAEvtOj3IMNNrw\nRUZIYAvwPFxTLXF0Dfj0fEiLFQzq+VPk3jsD9EbH1FotHXPtgA7brvG0uHfWKNsQ\nIQIDAQAB\n-----END PUBLIC KEY-----', + maintainer: 'Lightcurve GmbH', + }, + ], + backgroundColor: '#f7f9fb', + }, +}; + +export const liskTestnetApplication = { + '01000000': { + chainName: 'lisk_mainchain', + displayName: 'Lisk', + chainID: '01000000', + title: 'Lisk - Testnet', + description: 'Metadata configuration for the Lisk blockchain (mainchain) in testnet', + networkType: 'testnet', + isDefault: true, + status: 'activated', + genesisURL: 'https://downloads.lisk.com/lisk/testnet/genesis_block.json.tar.gz', + projectPage: 'https://lisk.com', + serviceURLs: [ + { + http: 'https://testnet-service.lisk.com', + ws: 'wss://testnet-service.lisk.com', + apiCertificatePublicKey: + '-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA55eVRxMsjgsakiSmRJGN\ng7u5XCO63BzbyFeUUuZ5YGRodFDw/cVAaIg9mWAtYRQM3FemJRt6zGcneFTbfmFC\nFcrGFbFqbcBssuHeyaBQroP8E5NcYVy7ZYJmZTaFBL9fpFzgrGdnLgjrlTkx7G+d\n95299QFRfX+mtSXuU0qzsSJzLaO9TsED3+I0aH80nJtxO8/ZI+RqjmomV5aAU0EO\n4S7a7npMZjxVKqwEcUcHeGf+4VLFGDc821IV45T4OZCxRG0sWgbc/AglY1xzRzJv\n1PTTWSYaukKM4rsuVEh6P12dAvMowh4wPGGPkQopXfS135xuHeefjnILl5/OcwHF\n3wIDAQAB\n-----END PUBLIC KEY-----', + }, + ], + logo: { + png: 'https://raw.githubusercontent.com/LiskHQ/app-registry/main/testnet/Lisk/images/application/lisk.png', + svg: 'https://raw.githubusercontent.com/LiskHQ/app-registry/main/testnet/Lisk/images/application/lisk.svg', + }, + explorers: [ + { + url: 'https://testnet.liskscan.com', + txnPage: 'https://testnet.liskscan.com/transactions', + }, + { + url: 'https://testnet.lisk.observer', + txnPage: 'https://testnet.lisk.observer/transactions', + }, + ], + appNodes: [ + { + url: 'https://testnet.lisk.com', + apiCertificatePublicKey: + '-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA55eVRxMsjgsakiSmRJGN\ng7u5XCO63BzbyFeUUuZ5YGRodFDw/cVAaIg9mWAtYRQM3FemJRt6zGcneFTbfmFC\nFcrGFbFqbcBssuHeyaBQroP8E5NcYVy7ZYJmZTaFBL9fpFzgrGdnLgjrlTkx7G+d\n95299QFRfX+mtSXuU0qzsSJzLaO9TsED3+I0aH80nJtxO8/ZI+RqjmomV5aAU0EO\n4S7a7npMZjxVKqwEcUcHeGf+4VLFGDc821IV45T4OZCxRG0sWgbc/AglY1xzRzJv\n1PTTWSYaukKM4rsuVEh6P12dAvMowh4wPGGPkQopXfS135xuHeefjnILl5/OcwHF\n3wIDAQAB\n-----END PUBLIC KEY-----', + maintainer: 'Lightcurve GmbH', + }, + { + url: 'wss://testnet.lisk.com', + apiCertificatePublicKey: + '-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA55eVRxMsjgsakiSmRJGN\ng7u5XCO63BzbyFeUUuZ5YGRodFDw/cVAaIg9mWAtYRQM3FemJRt6zGcneFTbfmFC\nFcrGFbFqbcBssuHeyaBQroP8E5NcYVy7ZYJmZTaFBL9fpFzgrGdnLgjrlTkx7G+d\n95299QFRfX+mtSXuU0qzsSJzLaO9TsED3+I0aH80nJtxO8/ZI+RqjmomV5aAU0EO\n4S7a7npMZjxVKqwEcUcHeGf+4VLFGDc821IV45T4OZCxRG0sWgbc/AglY1xzRzJv\n1PTTWSYaukKM4rsuVEh6P12dAvMowh4wPGGPkQopXfS135xuHeefjnILl5/OcwHF\n3wIDAQAB\n-----END PUBLIC KEY-----', + maintainer: 'Lightcurve GmbH', + }, + ], + backgroundColor: '#f7f9fb', + }, +}; diff --git a/src/modules/blockchainApplication/manage/hooks/useApplicationManagement.js b/src/modules/blockchainApplication/manage/hooks/useApplicationManagement.js index 60d37befea..c47914527c 100644 --- a/src/modules/blockchainApplication/manage/hooks/useApplicationManagement.js +++ b/src/modules/blockchainApplication/manage/hooks/useApplicationManagement.js @@ -6,6 +6,7 @@ import { selectApplications } from '../store/selectors'; import { useCurrentApplication } from './useCurrentApplication'; import { usePinBlockchainApplication } from './usePinBlockchainApplication'; import { useApplicationExploreAndMetaData } from './useApplicationExploreAndMetaData'; +import { liskMainnetApplication, liskTestnetApplication } from '../const/liskApplications'; // eslint-disable-next-line max-statements export function useApplicationManagement({ queryClient } = {}) { @@ -19,7 +20,8 @@ export function useApplicationManagement({ queryClient } = {}) { const { checkPinByChainId, pins } = usePinBlockchainApplication(); const applicationsObject = useSelector(selectApplications)[mainChainNetwork.name] || {}; - const networkApplications = useSelector(selectApplications) || {}; + const liskApplications = { mainnet: liskMainnetApplication, testnet: liskTestnetApplication }; + const networkApplications = useSelector(selectApplications) || { liskApplications }; const applications = useMemo(() => { const appsList = Object.values(applicationsObject).filter((app) => app?.status); From 52d683ad9790e06b84f0e737152e2e735e9fb717 Mon Sep 17 00:00:00 2001 From: Ikemefuna Obioha Date: Wed, 7 Aug 2024 15:51:59 +0100 Subject: [PATCH 09/16] Fixed network select and reload bugs --- src/locales/en/common.json | 1 + .../manage/hooks/useApplicationManagement.js | 4 +++- .../common/components/bars/sideBar/menuLinks.js | 8 ++++++++ src/modules/common/components/customRoute/index.js | 11 ++++++----- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/locales/en/common.json b/src/locales/en/common.json index c89924bca4..106f851b6d 100644 --- a/src/locales/en/common.json +++ b/src/locales/en/common.json @@ -789,6 +789,7 @@ "View profile": "View profile", "View remaining": "View remaining", "Volume": "Volume", + "Wallet": "Wallet", "Wallet address:": "Wallet address:", "Wallet balance": "Wallet balance", "Wallet connections": "Wallet connections", diff --git a/src/modules/blockchainApplication/manage/hooks/useApplicationManagement.js b/src/modules/blockchainApplication/manage/hooks/useApplicationManagement.js index c47914527c..5893ec8eac 100644 --- a/src/modules/blockchainApplication/manage/hooks/useApplicationManagement.js +++ b/src/modules/blockchainApplication/manage/hooks/useApplicationManagement.js @@ -21,7 +21,9 @@ export function useApplicationManagement({ queryClient } = {}) { const applicationsObject = useSelector(selectApplications)[mainChainNetwork.name] || {}; const liskApplications = { mainnet: liskMainnetApplication, testnet: liskTestnetApplication }; - const networkApplications = useSelector(selectApplications) || { liskApplications }; + const networkApplications = Object.keys(useSelector(selectApplications)).length + ? useSelector(selectApplications) + : { ...liskApplications }; const applications = useMemo(() => { const appsList = Object.values(applicationsObject).filter((app) => app?.status); diff --git a/src/modules/common/components/bars/sideBar/menuLinks.js b/src/modules/common/components/bars/sideBar/menuLinks.js index f5f2024cc8..e120cccecb 100644 --- a/src/modules/common/components/bars/sideBar/menuLinks.js +++ b/src/modules/common/components/bars/sideBar/menuLinks.js @@ -1,6 +1,14 @@ import routes from 'src/routes/routes'; const menuLinks = (t) => [ + [ + { + icon: 'walletIcon', + id: 'wallet', + label: t('Wallet'), + path: routes.wallet.path, + }, + ], [ { icon: 'applicationsIcon', diff --git a/src/modules/common/components/customRoute/index.js b/src/modules/common/components/customRoute/index.js index d786377405..ebd9b21d20 100644 --- a/src/modules/common/components/customRoute/index.js +++ b/src/modules/common/components/customRoute/index.js @@ -1,12 +1,11 @@ /* eslint-disable complexity */ -import React from 'react'; +import React, { useState } from 'react'; import { useSelector } from 'react-redux'; import { Redirect, Route } from 'react-router-dom'; import { useAccounts, useCurrentAccount } from '@account/hooks'; import Piwik from 'src/utils/piwik'; import routes from 'src/routes/routes'; import useSettings from '@settings/hooks/useSettings'; -import networks from '@network/configuration/networks'; import offlineStyle from 'src/modules/common/components/offlineWrapper/offlineWrapper.css'; import { useCheckLegacyAccount } from '@legacy/hooks/queries'; import { useTranslation } from 'react-i18next'; @@ -17,15 +16,17 @@ const CustomRoute = ({ path, exact, isPrivate, forbiddenTokens, component, histo const { t } = useTranslation(); const token = useSelector((state) => state.token); const isNetworkSet = useSelector(({ network }) => !!network.name); + const [isFirstTimeLoading, setIsFirstTimeLoading] = useState(true); const [currentAccount] = useCurrentAccount(); const { pubkey, address, isHW } = currentAccount?.metadata || {}; const isAuthenticated = !!address; const { isMigrated } = useCheckLegacyAccount(pubkey); const { search = '' } = history.location; const { accounts } = useAccounts(); - const { setValue: setMainChainNetwork } = useSettings('mainChainNetwork'); - if (!isNetworkSet) { - setMainChainNetwork(networks.mainnet); + const { mainChainNetwork, setValue: setMainChainNetwork } = useSettings('mainChainNetwork'); + if (isFirstTimeLoading) { + setMainChainNetwork(mainChainNetwork); + setIsFirstTimeLoading(false); } Piwik.tracking(history, token); From 781a20bbdc9c5a51ebe9b9fb4cee48ee75330b35 Mon Sep 17 00:00:00 2001 From: Ikemefuna Obioha Date: Thu, 8 Aug 2024 12:03:29 +0100 Subject: [PATCH 10/16] Rename legacy account hook --- src/modules/token/fungible/hooks/queries/useLiskLegacy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/token/fungible/hooks/queries/useLiskLegacy.js b/src/modules/token/fungible/hooks/queries/useLiskLegacy.js index c44b0492dd..d452cf9f06 100644 --- a/src/modules/token/fungible/hooks/queries/useLiskLegacy.js +++ b/src/modules/token/fungible/hooks/queries/useLiskLegacy.js @@ -3,7 +3,7 @@ import { useCustomQuery } from 'src/modules/common/hooks'; import { LISK_LEGACY } from 'src/const/queries'; import defaultClient from 'src/utils/api/client'; -export const useLiskLegacy = ({ +export const useLiskLegacyAccount = ({ config: customConfig = {}, options, client = defaultClient, From 2a3a302e4dd60914319a22cc2de22740ba13e9eb Mon Sep 17 00:00:00 2001 From: Ikemefuna Obioha Date: Thu, 8 Aug 2024 13:09:46 +0100 Subject: [PATCH 11/16] Rename legacy account file --- .../hooks/queries/{useLiskLegacy.js => useLiskLegacyAccount.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/modules/token/fungible/hooks/queries/{useLiskLegacy.js => useLiskLegacyAccount.js} (100%) diff --git a/src/modules/token/fungible/hooks/queries/useLiskLegacy.js b/src/modules/token/fungible/hooks/queries/useLiskLegacyAccount.js similarity index 100% rename from src/modules/token/fungible/hooks/queries/useLiskLegacy.js rename to src/modules/token/fungible/hooks/queries/useLiskLegacyAccount.js From 9989fc213ac5820618a874a69e552daa596f2550 Mon Sep 17 00:00:00 2001 From: Ikemefuna Obioha Date: Thu, 8 Aug 2024 13:15:04 +0100 Subject: [PATCH 12/16] Refactored overview based on PR review comment --- src/const/queries.js | 3 +- .../token/fungible/hooks/queries/index.js | 3 +- .../hooks/queries/useLiskLegacyAccount.js | 4 +- .../hooks/queries/useLiskLegacyHistory.js | 25 +++++++++++++ src/modules/transaction/utils/transaction.js | 9 +++++ .../wallet/components/overview/overview.js | 37 ++++++++++++------- 6 files changed, 63 insertions(+), 18 deletions(-) create mode 100644 src/modules/token/fungible/hooks/queries/useLiskLegacyHistory.js diff --git a/src/const/queries.js b/src/const/queries.js index d0cd200d81..e58ff96d48 100644 --- a/src/const/queries.js +++ b/src/const/queries.js @@ -6,7 +6,8 @@ export const TOKENS_BALANCE = 'GET_TOKENS_BALANCE'; export const TOKENS_SUPPORTED = 'GET_TOKENS_SUPPORTED'; export const TOKEN_BALANCES_TOP = 'GET_TOKEN_BALANCES_TOP'; export const TOKENS_ACCOUNT_EXISTS = 'GET_TOKENS_ACCOUNT_EXISTS'; -export const LISK_LEGACY = 'GET_LISK_LEGACY'; +export const LISK_LEGACY_ACCOUNT = 'GET_LISK_LEGACY_ACCOUNT'; +export const LISK_LEGACY_HISTORY = 'GET_LISK_LEGACY_HISTORY'; export const PEERS = 'GET_PEERS'; export const VALIDATORS = 'GET_VALIDATORS'; export const STAKES_SENT = 'GET_STAKES_SENT'; diff --git a/src/modules/token/fungible/hooks/queries/index.js b/src/modules/token/fungible/hooks/queries/index.js index 3fafff925c..4204219cff 100644 --- a/src/modules/token/fungible/hooks/queries/index.js +++ b/src/modules/token/fungible/hooks/queries/index.js @@ -8,4 +8,5 @@ export * from './useGetMinimumMessageFee'; export * from './useAppsMetaTokens'; export * from './useNetworkSupportedTokens'; export * from './useValidateFeeBalance'; -export * from './useLiskLegacy'; +export * from './useLiskLegacyAccount'; +export * from './useLiskLegacyHistory'; diff --git a/src/modules/token/fungible/hooks/queries/useLiskLegacyAccount.js b/src/modules/token/fungible/hooks/queries/useLiskLegacyAccount.js index d452cf9f06..0de2ac3682 100644 --- a/src/modules/token/fungible/hooks/queries/useLiskLegacyAccount.js +++ b/src/modules/token/fungible/hooks/queries/useLiskLegacyAccount.js @@ -1,6 +1,6 @@ import { useCurrentAccount } from 'src/modules/account/hooks'; import { useCustomQuery } from 'src/modules/common/hooks'; -import { LISK_LEGACY } from 'src/const/queries'; +import { LISK_LEGACY_ACCOUNT } from 'src/const/queries'; import defaultClient from 'src/utils/api/client'; export const useLiskLegacyAccount = ({ @@ -17,7 +17,7 @@ export const useLiskLegacyAccount = ({ }; return useCustomQuery({ - keys: [LISK_LEGACY], + keys: [LISK_LEGACY_ACCOUNT], config, options, client, diff --git a/src/modules/token/fungible/hooks/queries/useLiskLegacyHistory.js b/src/modules/token/fungible/hooks/queries/useLiskLegacyHistory.js new file mode 100644 index 0000000000..b4cded913f --- /dev/null +++ b/src/modules/token/fungible/hooks/queries/useLiskLegacyHistory.js @@ -0,0 +1,25 @@ +import { useCurrentAccount } from 'src/modules/account/hooks'; +import { useCustomQuery } from 'src/modules/common/hooks'; +import { LISK_LEGACY_HISTORY } from 'src/const/queries'; +import defaultClient from 'src/utils/api/client'; + +export const useLiskLegacyHistory = ({ + config: customConfig = {}, + options, + client = defaultClient, +} = {}) => { + const [currentAccount] = useCurrentAccount(); + const address = customConfig.params?.address || currentAccount.metadata?.address; + const config = { + url: `/histories/${address}.csv`, + method: 'get', + ...customConfig, + }; + + return useCustomQuery({ + keys: [LISK_LEGACY_HISTORY], + config, + options, + client, + }); +}; diff --git a/src/modules/transaction/utils/transaction.js b/src/modules/transaction/utils/transaction.js index a1b5be0c42..60ec66b032 100644 --- a/src/modules/transaction/utils/transaction.js +++ b/src/modules/transaction/utils/transaction.js @@ -163,6 +163,14 @@ const downloadJSON = (data, name) => { anchor.click(); }; +/* istanbul ignore next */ +const downloadCSV = (data, name) => { + const anchor = document.createElement('a'); + anchor.setAttribute('href', `data:text/csv;charset=utf-8,${encodeURIComponent(data)}`); + anchor.setAttribute('download', `${name}.csv`); + anchor.click(); +}; + /** * Removes the excess signatures from optional members * to open up room for the mandatory ones @@ -488,6 +496,7 @@ const normalizeNumberRange = (distributions) => { export { containsTransactionType, downloadJSON, + downloadCSV, getTransactionAmount, getUnsignedBytes, getNumberOfSignatures, diff --git a/src/modules/wallet/components/overview/overview.js b/src/modules/wallet/components/overview/overview.js index 502dd92741..9c5a43195a 100644 --- a/src/modules/wallet/components/overview/overview.js +++ b/src/modules/wallet/components/overview/overview.js @@ -1,10 +1,14 @@ -/* eslint-disable max-statements */ +/* eslint-disable max-statements, complexity */ import React, { useCallback, useEffect, useMemo } from 'react'; import { useSelector } from 'react-redux'; import { Link } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import grid from 'flexboxgrid/dist/flexboxgrid.css'; -import { useTokenBalances, useLiskLegacy } from '@token/fungible/hooks/queries'; +import { + useTokenBalances, + useLiskLegacyAccount, + useLiskLegacyHistory, +} from '@token/fungible/hooks/queries'; import TokenCard from '@wallet/components/TokenCard'; import TokenCarousel from '@wallet/components/TokenCarousel/TokenCarousel'; import { selectActiveTokenAccount } from 'src/redux/selectors'; @@ -22,7 +26,7 @@ import useSettings from 'src/modules/settings/hooks/useSettings'; import networks from 'src/modules/network/configuration/networks'; import { Client } from 'src/utils/api/client'; import routes from 'src/routes/routes'; -import { downloadJSON } from 'src/modules/transaction/utils'; +import { downloadCSV } from 'src/modules/transaction/utils'; import styles from './overview.css'; // 6: blocks per minute, 60: minutes, 24: hours @@ -44,7 +48,7 @@ const Overview = ({ isWalletRoute, history }) => { const { t } = useTranslation(); const [{ metadata: { address: currentAddress, name } = {} }] = useCurrentAccount(); const { mainChainNetwork } = useSettings('mainChainNetwork'); - const isTestnet = mainChainNetwork.serviceUrl === networks.testnet.serviceUrl; + const isMainnet = mainChainNetwork.serviceUrl === networks.mainnet.serviceUrl; const address = useMemo(() => searchAddress || currentAddress, [searchAddress, currentAddress]); const { data: validators } = useValidators({ config: { params: { address } } }); @@ -64,11 +68,16 @@ const Overview = ({ isWalletRoute, history }) => { legacyClient.create({ http: 'https://legacy.lisk.com/' }); const { - data: liskLegacy, - isLoading, - error, + data: liskLegacyAccount, + isLoading: isLoadingLegacyAccount, + error: errorLegacyAccount, refetch, - } = useLiskLegacy({ config: { params: { address } }, client: legacyClient }); + } = useLiskLegacyAccount({ config: { params: { address } }, client: legacyClient }); + const { + data: liskLegacyHistory, + isLoading: isLoadingLegacyHistory, + error: errorLegacyHistory, + } = useLiskLegacyHistory({ config: { params: { address } }, client: legacyClient }); const defaultLegacyBalance = { availableBalance: '0', lockedBalances: [{ module: 'pos', amount: '0' }], @@ -77,10 +86,10 @@ const Overview = ({ isWalletRoute, history }) => { svg: 'https://raw.githubusercontent.com/LiskHQ/app-registry/main/testnet/Lisk/images/tokens/lisk.svg', }, }; - const tokenLegacyBalance = liskLegacy + const tokenLegacyBalance = liskLegacyAccount ? [ { - ...liskLegacy.token, + ...liskLegacyAccount.token, symbol: 'LSK', logo: { svg: 'https://raw.githubusercontent.com/LiskHQ/app-registry/main/testnet/Lisk/images/tokens/lisk.svg', @@ -130,7 +139,7 @@ const Overview = ({ isWalletRoute, history }) => { useEffect(showWarning, [isWalletRoute, host, address, pomHeights]); const downloadAccountHistory = () => { - downloadJSON(liskLegacy, `${accountName}_account_history`); + downloadCSV(liskLegacyHistory, `${accountName}_account_history`); }; return ( @@ -151,7 +160,7 @@ const Overview = ({ isWalletRoute, history }) => { />
- {!isTestnet && ( + {isMainnet && !isLoadingLegacyHistory && !errorLegacyHistory && (
@@ -172,8 +181,8 @@ const Overview = ({ isWalletRoute, history }) => {
From 6e66d36f6312dd300c826f18f80dc65eb4883c0e Mon Sep 17 00:00:00 2001 From: Ikemefuna Obioha Date: Thu, 8 Aug 2024 14:20:59 +0100 Subject: [PATCH 13/16] Fixed tests --- .../components/bars/sideBar/index.test.js | 11 ++++--- .../components/customRoute/index.test.js | 1 + .../TokenCarousel/TokenCarousel.test.js | 31 +++++++++++++++++-- .../components/overview/overview.test.js | 25 ++++++++++----- 4 files changed, 55 insertions(+), 13 deletions(-) diff --git a/src/modules/common/components/bars/sideBar/index.test.js b/src/modules/common/components/bars/sideBar/index.test.js index 22f3f5db9d..35bec66be6 100644 --- a/src/modules/common/components/bars/sideBar/index.test.js +++ b/src/modules/common/components/bars/sideBar/index.test.js @@ -63,7 +63,8 @@ describe('SideBar', () => { }); it(`renders ${menuItems.length} menu items elements`, () => { - expect(wrapper).toContainMatchingElements(menuLinks.length, 'a'); + // Last two menu items are not anchor tags + expect(wrapper).toContainMatchingElements(menuItems.length - 2, 'a'); }); it('shows sidebar toggle info on hover', () => { @@ -75,12 +76,13 @@ describe('SideBar', () => { describe(`renders ${menuItems.length} menu items`, () => { it('without labels if sideBarExpanded is false', () => { - expect(wrapper).toContainMatchingElements(menuLinks.length, 'a'); + // Last two menu items are not anchor tags + expect(wrapper).toContainMatchingElements(menuItems.length - 2, 'a'); wrapper.find('a').forEach((link) => expect(link).not.toContain(/\w*/)); }); it('without labels if sideBarExpanded is true', () => { - const expectedLinks = ['Applications']; + const expectedLinks = ['Wallet', 'Applications']; mockAppState.settings = { ...mockAppState.settings, sideBarExpanded: true }; wrapper = mountWithRouter(SideBar, myProps); @@ -96,7 +98,8 @@ describe('SideBar', () => { pathname: routes.reclaim.path, }, }); - expect(wrapper).toContainMatchingElements(menuLinks.length, 'a'); + // Last two menu items are not anchor tags + expect(wrapper).toContainMatchingElements(menuItems.length - 2, 'a'); menuItems[0].forEach((_, index) => { expect(wrapper.find('a').at(index)).toHaveClassName('disabled'); }); diff --git a/src/modules/common/components/customRoute/index.test.js b/src/modules/common/components/customRoute/index.test.js index cd77d47a0f..97126261bf 100644 --- a/src/modules/common/components/customRoute/index.test.js +++ b/src/modules/common/components/customRoute/index.test.js @@ -61,6 +61,7 @@ describe('CustomRoute', () => { useSettings.mockReturnValue({ mainChainNetwork: { name: 'devnet' }, toggleSetting: mockToggleSetting, + setValue: jest.fn(), }); }); diff --git a/src/modules/wallet/components/TokenCarousel/TokenCarousel.test.js b/src/modules/wallet/components/TokenCarousel/TokenCarousel.test.js index 64e9d859c9..f7941726a2 100644 --- a/src/modules/wallet/components/TokenCarousel/TokenCarousel.test.js +++ b/src/modules/wallet/components/TokenCarousel/TokenCarousel.test.js @@ -25,7 +25,12 @@ describe('TokenCarousel', () => { const props = { renderItem: ({ item }) => `render-item-${item}`, data: [...new Array(2).keys()].map((item) => ({ item })), - error: 'error', + error: { + message: 'error', + response: { + status: 500, + }, + }, }; wrapper = render(); @@ -34,7 +39,12 @@ describe('TokenCarousel', () => { expect(screen.queryByText(`render-item-${item}`)).toBeFalsy(); }); - props.error = { message: 'error' }; + props.error = { + message: 'error', + response: { + status: 500, + }, + }; wrapper.rerender(); expect(screen.queryByText('error')).toBeTruthy(); @@ -45,6 +55,23 @@ describe('TokenCarousel', () => { }); }); + it('should not display an error for HTTP 404 status', async () => { + const props = { + renderItem: ({ item }) => `render-item-${item}`, + data: [...new Array(2).keys()].map((item) => ({ item })), + error: { + message: 'error', + response: { + status: 404, + }, + }, + }; + wrapper = render(); + + expect(screen.queryByText('error')).toBeFalsy(); + expect(screen.queryByText('Retry')).toBeFalsy(); + }); + it('should display a loading state skeleton', async () => { const props = { renderItem: ({ item }) => `render-item-${item}`, diff --git a/src/modules/wallet/components/overview/overview.test.js b/src/modules/wallet/components/overview/overview.test.js index f65e189155..caa574e6b7 100644 --- a/src/modules/wallet/components/overview/overview.test.js +++ b/src/modules/wallet/components/overview/overview.test.js @@ -3,7 +3,11 @@ import { MemoryRouter } from 'react-router'; import { render, screen } from '@testing-library/react'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import mockSavedAccounts from '@tests/fixtures/accounts'; -import { useTokenBalances, useLiskLegacy } from '@token/fungible/hooks/queries'; +import { + useTokenBalances, + useLiskLegacyAccount, + useLiskLegacyHistory, +} from '@token/fungible/hooks/queries'; import { useValidators } from '@pos/validator/hooks/queries'; import { useAuth } from '@auth/hooks/queries'; @@ -24,6 +28,13 @@ jest.mock('@account/hooks', () => ({ })); jest.mock('@token/fungible/hooks/queries'); +jest.mock('@settings/hooks/useSettings', () => ({ + __esModule: true, + default: jest.fn(() => ({ + mainChainNetwork: { name: 'mainnet' }, + setValue: jest.fn(), + })), +})); jest.mock('@account/hooks'); jest.mock('@pos/validator/hooks/queries', () => ({ useValidators: jest.fn(), @@ -36,11 +47,6 @@ jest.mock('src/modules/common/hooks/useFiatRates'); describe('Overview', () => { const history = { location: { search: '' } }; - const mergedTokens = mockAppsTokens.data.map((token, index) => ({ - ...mockTokensBalance.data[index], - ...token, - })); - useFiatRates.mockReturnValue({ LSK: { USD: 1, EUR: 1 } }); it('should display properly', async () => { @@ -57,7 +63,7 @@ describe('Overview', () => { isLoading: false, isSuccess: true, }); - useLiskLegacy.mockReturnValue({ + useLiskLegacyAccount.mockReturnValue({ data: { token: { availableBalance: '1586739386', @@ -73,6 +79,11 @@ describe('Overview', () => { isLoading: false, isSuccess: true, }); + useLiskLegacyHistory.mockReturnValue({ + data: "Version,Block Height,Date,Sender Address,Amount,Transaction ID,Transaction Type,Transaction Fee,Success,Recipient Address,Additional Information,Comment,\nv1,2199158,2017-02-28 12:32:40 +0000 UTC,lskgtrrftvoxhtknhamjab5wenfauk32z9pzk79uj,2500000000,16167385358120905513,token_transfer,0,true,lskervnyptonqvc4byqz5jsnded4gd264tacqzx9p,,3766202724911711412L's new address is lskervnyptonqvc4byqz5jsnded4gd264tacqzx9p.", + isLoading: false, + isSuccess: true, + }); useAuth.mockReturnValue({ data: mockAuth }); useValidators.mockReturnValue({ data: mockValidators }); useBlocks.mockReturnValue({ data: mockBlocks }); From e4a9e84a210273e86a10596b9828d024a4667f18 Mon Sep 17 00:00:00 2001 From: Ikemefuna Obioha Date: Thu, 8 Aug 2024 16:42:36 +0100 Subject: [PATCH 14/16] Added fallback for account details display --- src/modules/wallet/components/overview/overview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/wallet/components/overview/overview.js b/src/modules/wallet/components/overview/overview.js index 9c5a43195a..0b0b51b3f7 100644 --- a/src/modules/wallet/components/overview/overview.js +++ b/src/modules/wallet/components/overview/overview.js @@ -151,7 +151,7 @@ const Overview = ({ isWalletRoute, history }) => { Date: Fri, 9 Aug 2024 14:08:35 +0100 Subject: [PATCH 15/16] Fix continue button disabled bug during application signing --- .../connection/components/RequestSummary/index.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/modules/blockchainApplication/connection/components/RequestSummary/index.js b/src/modules/blockchainApplication/connection/components/RequestSummary/index.js index 9afd2d7c75..9615a3f2f9 100644 --- a/src/modules/blockchainApplication/connection/components/RequestSummary/index.js +++ b/src/modules/blockchainApplication/connection/components/RequestSummary/index.js @@ -15,7 +15,6 @@ import { SIGNING_METHODS } from '@libs/wcm/constants/permissions'; import { EVENTS } from '@libs/wcm/constants/lifeCycle'; import { useAppsMetaTokens } from '@token/fungible/hooks/queries/useAppsMetaTokens'; import { toTransactionJSON } from '@transaction/utils/encoding'; -import { useBlockchainApplicationMeta } from '@blockchainApplication/manage/hooks/queries/useBlockchainApplicationMeta'; import { convertFromBaseDenom } from '@token/fungible/utils/helpers'; import { joinModuleAndCommand } from '@transaction/utils/moduleCommand'; import { signMessage, signClaimMessage } from '@message/store/action'; @@ -54,7 +53,6 @@ const RequestSummary = ({ nextStep, history, message, portalMessage }) => { const [errorMessage, setErrorMessage] = useState(''); const { sessionRequest, respond } = useSession({ isEnabled: !message }); const reduxDispatch = useDispatch(); - const metaData = useBlockchainApplicationMeta(); useDeprecatedAccount(senderAccount); useSchemas(); @@ -309,11 +307,7 @@ const RequestSummary = ({ nextStep, history, message, portalMessage }) => { className={styles.button} onClick={!encryptedSenderAccount ? navigateToAddAccountFlow : approveHandler} data-testid="approve-button" - disabled={ - !metaData.data || - errorMessage || - (!isSenderCurrentAccount && !!encryptedSenderAccount) - } + disabled={errorMessage || (!isSenderCurrentAccount && !!encryptedSenderAccount)} > {!encryptedSenderAccount ? t('Add account') : t('Continue')} From 094b950dfc39801e7fad693ee12def44a1999809 Mon Sep 17 00:00:00 2001 From: Ikemefuna Obioha Date: Mon, 12 Aug 2024 11:05:00 +0100 Subject: [PATCH 16/16] Update lockfile to fix numeral package issue --- yarn.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn.lock b/yarn.lock index 9e48fdee09..2a872d0758 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12243,7 +12243,7 @@ num2fraction@^1.2.2: "numeral@git+https://github.com/LiskHQ/Numeral-js.git": version "2.0.6" - resolved "git+https://github.com/LiskHQ/Numeral-js.git#195af9768f998c4e4acde3ec86388b17c7c0254b" + resolved "git+https://github.com/LiskHQ/Numeral-js.git#3673d4898e8b58c609b104e5c4e615d4e429f66d" nwsapi@^2.0.7, nwsapi@^2.2.2: version "2.2.5"