Skip to content

Commit

Permalink
fix unnecessary calls for guardian data
Browse files Browse the repository at this point in the history
  • Loading branch information
juliancwirko committed Sep 23, 2023
1 parent 8d753fb commit c14ec4b
Show file tree
Hide file tree
Showing 7 changed files with 550 additions and 489 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### [0.9.2](https://github.com/useElven/core/releases/tag/v0.9.2) (2023-09-23)
- fix unnecessary calls for guardian data
- update dependencies

### [0.9.1](https://github.com/useElven/core/releases/tag/v0.9.1) (2023-08-27)
- add 'use client' banner (preparing for better support of the Next.js 'app router' architecture)
- update dependencies
Expand Down
984 changes: 520 additions & 464 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@useelven/core",
"version": "0.9.1",
"version": "0.9.2",
"description": "Core hooks for MultiversX React DApps",
"license": "MIT",
"author": "Julian Ćwirko <julian.io>",
Expand Down Expand Up @@ -36,7 +36,7 @@
"access": "public"
},
"engines": {
"node": "^14.13.1 || >=16.0.0"
"node": ">=16.0.0"
},
"tsup": {
"banner": {
Expand All @@ -63,31 +63,31 @@
"prepublishOnly": "npm run build"
},
"dependencies": {
"@multiversx/sdk-core": "12.7.1",
"@multiversx/sdk-core": "12.9.0",
"@multiversx/sdk-extension-provider": "3.0.0",
"@multiversx/sdk-hw-provider": "6.4.0",
"@multiversx/sdk-native-auth-client": "1.0.5",
"@multiversx/sdk-network-providers": "2.0.0",
"@multiversx/sdk-wallet-connect-provider": "4.0.3",
"@multiversx/sdk-web-wallet-provider": "3.0.0",
"@multiversx/sdk-web-wallet-provider": "3.1.0",
"lodash.clonedeep": "4.5.0",
"swr": "2.2.2",
"valtio": "1.11.2"
},
"devDependencies": {
"@types/lodash.clonedeep": "4.5.7",
"@types/node": "20.5.6",
"@types/react": "18.2.21",
"@typescript-eslint/eslint-plugin": "6.4.1",
"@typescript-eslint/parser": "6.4.1",
"eslint": "8.48.0",
"@types/node": "20.6.3",
"@types/react": "18.2.22",
"@typescript-eslint/eslint-plugin": "6.7.2",
"@typescript-eslint/parser": "6.7.2",
"eslint": "8.50.0",
"eslint-config-prettier": "9.0.0",
"eslint-plugin-prettier": "5.0.0",
"eslint-plugin-react": "7.33.2",
"eslint-plugin-react-hooks": "4.6.0",
"prettier": "3.0.2",
"prettier": "3.0.3",
"rimraf": "5.0.1",
"terser": "5.19.2",
"terser": "5.20.0",
"tsup": "7.2.0",
"typescript": "5.2.2"
},
Expand Down
9 changes: 6 additions & 3 deletions src/hooks/common-helpers/useAccountNetworkSync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import { setAccountState, setLoggingInState } from '../../store/auth';
import { Address, Account } from '@multiversx/sdk-core';
import { useAccount } from '../useAccount';
import { useLoginInfo } from '../useLoginInfo';
import { useLogout } from '../useLogout';

export const useAccountNetworkSync = (
apiNetworkProviderRef: MutableRefObject<ApiNetworkProvider | undefined>
) => {
const { logout } = useLogout();
const accountSnap = useAccount();
const loginInfoSnap = useLoginInfo();

Expand All @@ -25,9 +27,8 @@ export const useAccountNetworkSync = (
const userAddressInstance = new Address(address);
const userAccountInstance = new Account(userAddressInstance);
try {
const userAccountOnNetwork = await apiNetworkProvider.getAccount(
userAddressInstance
);
const userAccountOnNetwork =
await apiNetworkProvider.getAccount(userAddressInstance);
const userGuardianOnNetwork =
await apiNetworkProvider.getGuardianData(userAddressInstance);

Expand All @@ -51,6 +52,8 @@ export const useAccountNetworkSync = (
} finally {
setLoggingInState('pending', false);
}
} else {
logout();
}
};

Expand Down
3 changes: 2 additions & 1 deletion src/hooks/useExtensionLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ export const useExtensionLogin = (params?: Login) => {
const userAddressInstance = new Address(address);
const userAccountInstance = new Account(userAddressInstance);

if (networkStateSnap.apiNetworkProvider) {
if (networkStateSnap.apiNetworkProvider && address) {
try {
const userAccountOnNetwork =
await networkStateSnap.apiNetworkProvider.getAccount(
userAddressInstance
);

const userGuardianOnNetwork =
await networkStateSnap.apiNetworkProvider.getGuardianData(
userAddressInstance
Expand Down
5 changes: 2 additions & 3 deletions src/hooks/useLedgerLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ export const useLedgerLogin = (params?: Login) => {
if (apiNetworkProvider) {
const addressInstance = new Address(userAddress);
const userAccountInstance = new Account(addressInstance);
const userAccountOnNetwork = await apiNetworkProvider.getAccount(
addressInstance
);
const userAccountOnNetwork =
await apiNetworkProvider.getAccount(addressInstance);
const userGuardianOnNetwork =
await apiNetworkProvider.getGuardianData(addressInstance);

Expand Down
12 changes: 5 additions & 7 deletions src/utils/walletConnectCbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ export const WcOnLogin = async (
const userAddressInstance = new Address(address);
const userAccountInstance = new Account(userAddressInstance);

if (apiNetworkProvider) {
if (apiNetworkProvider && address) {
try {
const userAccountOnNetwork = await apiNetworkProvider.getAccount(
userAddressInstance
);
const userGuardianOnNetwork = await apiNetworkProvider.getGuardianData(
userAddressInstance
);
const userAccountOnNetwork =
await apiNetworkProvider.getAccount(userAddressInstance);
const userGuardianOnNetwork =
await apiNetworkProvider.getGuardianData(userAddressInstance);
userAccountInstance.update(userAccountOnNetwork);
setAccountState('address', userAccountInstance.address.bech32());
setAccountState(
Expand Down

0 comments on commit c14ec4b

Please sign in to comment.