From 4f1e8b976a3dc01305c8adcafc59907eeba6a056 Mon Sep 17 00:00:00 2001 From: "razvan.tomegea" Date: Tue, 26 Nov 2024 16:26:44 +0200 Subject: [PATCH 01/12] Updated get network config from API logic --- CHANGELOG.md | 2 ++ .../ProviderInitializer/ProviderInitializer.tsx | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7957cf0f9..d94d8c7ea 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] +- [Updated get network config from API logic](https://github.com/multiversx/mx-sdk-dapp/pull/1317) + ## [[v3.0.15](https://github.com/multiversx/mx-sdk-dapp/pull/1316)] - 2024-11-25 - [Added transaction data decoder](https://github.com/multiversx/mx-sdk-dapp/pull/1311) diff --git a/src/components/ProviderInitializer/ProviderInitializer.tsx b/src/components/ProviderInitializer/ProviderInitializer.tsx index 7d25fbdd7..9554c7829 100644 --- a/src/components/ProviderInitializer/ProviderInitializer.tsx +++ b/src/components/ProviderInitializer/ProviderInitializer.tsx @@ -60,6 +60,11 @@ import { getIframeProvider } from './helpers'; import { useSetLedgerProvider } from './hooks'; +import { + DEVNET_CHAIN_ID, + MAINNET_CHAIN_ID, + TESTNET_CHAIN_ID +} from '../../constants'; let initalizingLedger = false; @@ -116,6 +121,16 @@ export function ProviderInitializer() { }, [ledgerAccount, isLoggedIn, ledgerData]); async function refreshNetworkConfig() { + const shouldGetConfig = + !network.chainId || + ![DEVNET_CHAIN_ID, TESTNET_CHAIN_ID, MAINNET_CHAIN_ID].includes( + network.chainId + ); + + if (!shouldGetConfig) { + return; + } + try { const networkConfig = await getNetworkConfigFromApi(); const hasDifferentNetworkConfig = From f6f6b8d17bd72909f19e734abb2bf2fcd596e9d6 Mon Sep 17 00:00:00 2001 From: "razvan.tomegea" Date: Tue, 26 Nov 2024 16:27:06 +0200 Subject: [PATCH 02/12] Updated package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index da31e30b6..6efed662f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@multiversx/sdk-dapp", - "version": "3.0.15", + "version": "3.0.16-alpha.0", "description": "A library to hold the main logic for a dapp on the MultiversX blockchain", "author": "MultiversX", "license": "GPL-3.0-or-later", From a21676670341d1441fbd4fbfff39820db4b40886 Mon Sep 17 00:00:00 2001 From: "razvan.tomegea" Date: Tue, 26 Nov 2024 16:32:32 +0200 Subject: [PATCH 03/12] CHANGELOG.md --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0efa77e71..774e8fa84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,13 +5,13 @@ All notable changes will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [[v3.0.16](https://github.com/multiversx/mx-sdk-dapp/pull/1318)] - 2024-11-26 +## [Unreleased] -- [Updated provider initializer to use useGetAccountFromApi](https://github.com/multiversx/mx-sdk-dapp/pull/1317) +- [Updated get network config from API logic](https://github.com/multiversx/mx-sdk-dapp/pull/1319) -## [Unreleased] +## [[v3.0.16](https://github.com/multiversx/mx-sdk-dapp/pull/1318)] - 2024-11-26 -- [Updated get network config from API logic](https://github.com/multiversx/mx-sdk-dapp/pull/1317) +- [Updated provider initializer to use useGetAccountFromApi](https://github.com/multiversx/mx-sdk-dapp/pull/1317) ## [[v3.0.15](https://github.com/multiversx/mx-sdk-dapp/pull/1316)] - 2024-11-25 From 4ff688f3383f17341596603bc4fe39ab29f14c05 Mon Sep 17 00:00:00 2001 From: "razvan.tomegea" Date: Tue, 26 Nov 2024 16:33:44 +0200 Subject: [PATCH 04/12] Workflows --- .github/workflows/npm-publish.yml | 2 +- .github/workflows/pre-merge-unit-tests.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index c697ee090..01b83dff0 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -30,7 +30,7 @@ jobs: run: yarn install - name: Run tests - run: yarn test + run: yarn test --silent - name: Build project run: yarn build diff --git a/.github/workflows/pre-merge-unit-tests.yml b/.github/workflows/pre-merge-unit-tests.yml index 380b0ae9e..fbdac2815 100644 --- a/.github/workflows/pre-merge-unit-tests.yml +++ b/.github/workflows/pre-merge-unit-tests.yml @@ -37,4 +37,4 @@ jobs: - name: Build run: yarn build - name: Run unit tests - run: yarn test + run: yarn test --silent From a6c905b0770978e2166295a53feefffaf8310f0a Mon Sep 17 00:00:00 2001 From: "razvan.tomegea" Date: Tue, 26 Nov 2024 17:30:57 +0200 Subject: [PATCH 05/12] 3.0.17 --- CHANGELOG.md | 2 ++ package.json | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 774e8fa84..b518dc804 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] +## [[v3.0.17](https://github.com/multiversx/mx-sdk-dapp/pull/1320)] - 2024-11-26 + - [Updated get network config from API logic](https://github.com/multiversx/mx-sdk-dapp/pull/1319) ## [[v3.0.16](https://github.com/multiversx/mx-sdk-dapp/pull/1318)] - 2024-11-26 diff --git a/package.json b/package.json index cd54fb7e9..b2dbfc25d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@multiversx/sdk-dapp", - "version": "3.0.17-alpha.0", + "version": "3.0.17", "description": "A library to hold the main logic for a dapp on the MultiversX blockchain", "author": "MultiversX", "license": "GPL-3.0-or-later", From 6c9c35124e03aa7c9de504d83456e313cd12431a Mon Sep 17 00:00:00 2001 From: "razvan.tomegea" Date: Tue, 26 Nov 2024 17:32:16 +0200 Subject: [PATCH 06/12] Lint --- .../ProviderInitializer/ProviderInitializer.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/ProviderInitializer/ProviderInitializer.tsx b/src/components/ProviderInitializer/ProviderInitializer.tsx index c0669a72c..45e05c609 100644 --- a/src/components/ProviderInitializer/ProviderInitializer.tsx +++ b/src/components/ProviderInitializer/ProviderInitializer.tsx @@ -1,5 +1,10 @@ import { useEffect, useRef } from 'react'; import { getNetworkConfigFromApi, useGetAccountFromApi } from 'apiCalls'; +import { + DEVNET_CHAIN_ID, + MAINNET_CHAIN_ID, + TESTNET_CHAIN_ID +} from 'constants/index'; import { useLoginService } from 'hooks/login/useLoginService'; import { useWalletConnectV2Login } from 'hooks/login/useWalletConnectV2Login'; import { useWebViewLogin } from 'hooks/login/useWebViewLogin'; @@ -59,11 +64,6 @@ import { getIframeProvider } from './helpers'; import { useSetLedgerProvider } from './hooks'; -import { - DEVNET_CHAIN_ID, - MAINNET_CHAIN_ID, - TESTNET_CHAIN_ID -} from '../../constants'; let initalizingLedger = false; From 50ffdd1a71f756b996e870484809841e5ee65002 Mon Sep 17 00:00:00 2001 From: "razvan.tomegea" Date: Tue, 26 Nov 2024 21:38:08 +0200 Subject: [PATCH 07/12] Removed refreshAccount on websocket event --- CHANGELOG.md | 2 ++ src/hooks/transactions/useTransactionsTracker.ts | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b518dc804..108be15e4 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] +- [Removed refreshAccount on websocket event](https://github.com/multiversx/mx-sdk-dapp/pull/1321) + ## [[v3.0.17](https://github.com/multiversx/mx-sdk-dapp/pull/1320)] - 2024-11-26 - [Updated get network config from API logic](https://github.com/multiversx/mx-sdk-dapp/pull/1319) diff --git a/src/hooks/transactions/useTransactionsTracker.ts b/src/hooks/transactions/useTransactionsTracker.ts index 7133e51ba..5dae5106e 100644 --- a/src/hooks/transactions/useTransactionsTracker.ts +++ b/src/hooks/transactions/useTransactionsTracker.ts @@ -21,7 +21,6 @@ export function useTransactionsTracker(props?: TransactionsTrackerType) { const onMessage = () => { checkTransactionStatus({ - shouldRefreshBalance: isWebsocketCompleted, getTransactionsByHash, ...props }); From 6164803620bfaa5469608b56a676cfe5a02be457 Mon Sep 17 00:00:00 2001 From: "razvan.tomegea" Date: Tue, 26 Nov 2024 21:38:47 +0200 Subject: [PATCH 08/12] Fixed Ledger login --- src/hooks/login/useLedgerLogin.ts | 51 ++++++++++++++++++------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/hooks/login/useLedgerLogin.ts b/src/hooks/login/useLedgerLogin.ts index e09323b37..5a4bbe50b 100644 --- a/src/hooks/login/useLedgerLogin.ts +++ b/src/hooks/login/useLedgerLogin.ts @@ -116,18 +116,16 @@ export const useLedgerLogin = ({ }; const onLoginFailed = (err: any, customMessage = '') => { - if (!err) { - return; - } + if (isLoading) { + const { errorMessage, defaultErrorMessage } = getLedgerErrorCodes(err); - const { errorMessage, defaultErrorMessage } = getLedgerErrorCodes(err); + const message = + errorMessage ?? defaultErrorMessage ?? failInitializeErrorText; - const message = - errorMessage ?? defaultErrorMessage ?? failInitializeErrorText; - - setError(`${message}.${customMessage}`); - setIsLoading(false); - dispatch(setLedgerAccount(null)); + setError(`${message}.${customMessage}`); + setIsLoading(false); + dispatch(setLedgerAccount(null)); + } }; const isHWProviderInitialized = async () => { @@ -239,12 +237,10 @@ export const useLedgerLogin = ({ ); } - setIsLoading(false); await loginUser(); + setIsLoading(false); } catch (err) { onLoginFailed(err); - } finally { - setIsLoading(false); } setShowAddressList(false); @@ -283,12 +279,10 @@ export const useLedgerLogin = ({ } clearInitiatedLogins(); - setError(''); try { setIsLoading(true); - await initHWProvider(); const isInitialized = await isHWProviderInitialized(); if (!isInitialized) { @@ -323,19 +317,32 @@ export const useLedgerLogin = ({ setShowAddressList(true); } - } catch (error) { - onLoginFailed(error); - } finally { + setIsLoading(false); + } catch (err) { + onLoginFailed(err); } }; - useEffect(() => { - initHWProvider(); - }, [hwProvider]); + const initProviderAndAccounts = async () => { + try { + await initHWProvider(); + const isInitialized = await isHWProviderInitialized(); + + if (!isInitialized) { + return onLoginFailed(failInitializeErrorText); + } + + if (accounts.length === 0 || startIndex > 0) { + await fetchAccounts(); + } + } catch (err) { + onLoginFailed(err, failInitializeErrorText); + } + }; useEffect(() => { - fetchAccounts(); + initProviderAndAccounts(); }, [startIndex, showAddressList, hwProvider]); useEffect(() => { From 94c539d6f2c348b0afea8aca3251e13bef28b0c7 Mon Sep 17 00:00:00 2001 From: "razvan.tomegea" Date: Tue, 26 Nov 2024 21:38:53 +0200 Subject: [PATCH 09/12] Fixed Ledger login --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 108be15e4..4183b4a52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- [Fixed Ledger login](https://github.com/multiversx/mx-sdk-dapp/pull/1322) - [Removed refreshAccount on websocket event](https://github.com/multiversx/mx-sdk-dapp/pull/1321) ## [[v3.0.17](https://github.com/multiversx/mx-sdk-dapp/pull/1320)] - 2024-11-26 From 2a215cf5e6ab3266bc98ca56b7297e9fbdab7bbe Mon Sep 17 00:00:00 2001 From: "razvan.tomegea" Date: Wed, 27 Nov 2024 16:13:20 +0200 Subject: [PATCH 10/12] Refactor --- CHANGELOG.md | 1 + src/hooks/login/useLedgerLogin.ts | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 086895b4e..869a3f7a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- [Fixed Ledger login](https://github.com/multiversx/mx-sdk-dapp/pull/1321) - [Removed refreshAccount on websocket event](https://github.com/multiversx/mx-sdk-dapp/pull/1320) - [Updated get network config from API logic](https://github.com/multiversx/mx-sdk-dapp/pull/1319) diff --git a/src/hooks/login/useLedgerLogin.ts b/src/hooks/login/useLedgerLogin.ts index 5a4bbe50b..9d7849d6c 100644 --- a/src/hooks/login/useLedgerLogin.ts +++ b/src/hooks/login/useLedgerLogin.ts @@ -116,6 +116,7 @@ export const useLedgerLogin = ({ }; const onLoginFailed = (err: any, customMessage = '') => { + // Show errors only if the user initiated the login process (isLoading is true) if (isLoading) { const { errorMessage, defaultErrorMessage } = getLedgerErrorCodes(err); @@ -324,10 +325,17 @@ export const useLedgerLogin = ({ } }; + // Need to initialise the HWProvider before starting the login process + // and fetch the accounts immediately afterward only once const initProviderAndAccounts = async () => { try { - await initHWProvider(); - const isInitialized = await isHWProviderInitialized(); + let isInitialized = await isHWProviderInitialized(); + + if (!isInitialized) { + await initHWProvider(); + } + + isInitialized = await isHWProviderInitialized(); if (!isInitialized) { return onLoginFailed(failInitializeErrorText); @@ -337,7 +345,7 @@ export const useLedgerLogin = ({ await fetchAccounts(); } } catch (err) { - onLoginFailed(err, failInitializeErrorText); + onLoginFailed(err); } }; From 267e68fd9891c8ac2917e55e6f6393ea2e173b1c Mon Sep 17 00:00:00 2001 From: "razvan.tomegea" Date: Wed, 27 Nov 2024 16:14:29 +0200 Subject: [PATCH 11/12] Comment --- src/hooks/login/useLedgerLogin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hooks/login/useLedgerLogin.ts b/src/hooks/login/useLedgerLogin.ts index 9d7849d6c..0e60de0ca 100644 --- a/src/hooks/login/useLedgerLogin.ts +++ b/src/hooks/login/useLedgerLogin.ts @@ -326,7 +326,7 @@ export const useLedgerLogin = ({ }; // Need to initialise the HWProvider before starting the login process - // and fetch the accounts immediately afterward only once + // and fetch the accounts immediately afterward only once or if the address page changes const initProviderAndAccounts = async () => { try { let isInitialized = await isHWProviderInitialized(); From af1908146135c43010f38d04b95a072aa311f6c8 Mon Sep 17 00:00:00 2001 From: "razvan.tomegea" Date: Wed, 27 Nov 2024 16:16:01 +0200 Subject: [PATCH 12/12] jest.config.js --- jest.config.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jest.config.js b/jest.config.js index 2f1e5bc04..bbde8a011 100644 --- a/jest.config.js +++ b/jest.config.js @@ -37,5 +37,7 @@ module.exports = { watchPlugins: [ 'jest-watch-typeahead/filename', 'jest-watch-typeahead/testname' - ] + ], + workerIdleMemoryLimit: '512MB', // Memory used per worker. Required to prevent memory leaks + maxWorkers: '50%' // Maximum tests ran in parallel. Required to prevent CPU usage at 100% };