From 82a9668b1ba8858ed1722876345e84b9fa9ad3ce Mon Sep 17 00:00:00 2001 From: enesozturk Date: Tue, 13 Feb 2024 11:23:37 +0300 Subject: [PATCH 1/2] feat: add loading state to useWeb3ModalState hook --- packages/core/src/controllers/PublicStateController.ts | 2 ++ packages/scaffold/src/client.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/core/src/controllers/PublicStateController.ts b/packages/core/src/controllers/PublicStateController.ts index f4b91511a2..03f83ed2da 100644 --- a/packages/core/src/controllers/PublicStateController.ts +++ b/packages/core/src/controllers/PublicStateController.ts @@ -3,12 +3,14 @@ import type { CaipNetworkId } from '../utils/TypeUtil.js' // -- Types --------------------------------------------- // export interface PublicStateControllerState { + loading: boolean open: boolean selectedNetworkId?: CaipNetworkId } // -- State --------------------------------------------- // const state = proxy({ + loading: false, open: false, selectedNetworkId: undefined }) diff --git a/packages/scaffold/src/client.ts b/packages/scaffold/src/client.ts index e3d760a4a6..596e21fc05 100644 --- a/packages/scaffold/src/client.ts +++ b/packages/scaffold/src/client.ts @@ -130,7 +130,7 @@ export class Web3ModalScaffold { } public getState() { - return { ...PublicStateController.state } + return { ...PublicStateController.state, loading: ModalController.state.loading } } public subscribeState(callback: (newState: PublicStateControllerState) => void) { From 4835511989da371da2b1e3a297316e7e273b58b4 Mon Sep 17 00:00:00 2001 From: enesozturk Date: Thu, 29 Feb 2024 23:38:01 +0300 Subject: [PATCH 2/2] refactor: sync public state controller loading state with modal controller --- packages/core/src/controllers/ModalController.ts | 1 + packages/scaffold/src/client.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/core/src/controllers/ModalController.ts b/packages/core/src/controllers/ModalController.ts index 4ed0a37f60..b492adc6d6 100644 --- a/packages/core/src/controllers/ModalController.ts +++ b/packages/core/src/controllers/ModalController.ts @@ -71,5 +71,6 @@ export const ModalController = { setLoading(loading: ModalControllerState['loading']) { state.loading = loading + PublicStateController.set({ loading }) } } diff --git a/packages/scaffold/src/client.ts b/packages/scaffold/src/client.ts index 596e21fc05..eb5bcb2213 100644 --- a/packages/scaffold/src/client.ts +++ b/packages/scaffold/src/client.ts @@ -130,7 +130,7 @@ export class Web3ModalScaffold { } public getState() { - return { ...PublicStateController.state, loading: ModalController.state.loading } + return PublicStateController.state } public subscribeState(callback: (newState: PublicStateControllerState) => void) {