Skip to content

Commit 6c84476

Browse files
committed
cleanup on config changes in vue
1 parent 06c5f4e commit 6c84476

File tree

6 files changed

+58
-40
lines changed

6 files changed

+58
-40
lines changed

demo/vue-app-new/package-lock.json

Lines changed: 23 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/vue-app-new/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@
1212
"dependencies": {
1313
"@solana/web3.js": "^1.98.0",
1414
"@toruslabs/base-controllers": "^8.1.0",
15+
"@toruslabs/bs58": "^1.0.0",
1516
"@toruslabs/ethereum-controllers": "^8.2.0",
1617
"@toruslabs/solana-controllers": "^8.1.0",
18+
"@toruslabs/tweetnacl-js": "^1.0.4",
1719
"@toruslabs/vue-components": "^8.0.6",
1820
"@toruslabs/vue-icons": "^8.0.2",
19-
"@web3auth/auth": "^10.3.0",
21+
"@web3auth/auth": "^10.4.0",
2022
"@web3auth/modal": "file:../../packages/modal",
2123
"@web3auth/no-modal": "file:../../packages/no-modal",
2224
"@web3auth/sign-in-with-ethereum": "^5.0.0",
2325
"@web3auth/ws-embed": "^5.0.0",
24-
"@toruslabs/bs58": "^1.0.0",
2526
"ethers": "^6.13.5",
2627
"petite-vue-i18n": "^11.1.3",
27-
"@toruslabs/tweetnacl-js": "^1.0.4",
2828
"vue": "^3.5.13"
2929
},
3030
"devDependencies": {

packages/modal/src/ui/loginModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ export class LoginModal {
242242
</ThemedContext.Provider>
243243
);
244244

245-
const isDefaultColors = this.uiConfig?.theme.primary === DEFAULT_PRIMARY_COLOR && this.uiConfig.theme.onPrimary === DEFAULT_ON_PRIMARY_COLOR;
245+
const isDefaultColors = this.uiConfig?.theme?.primary === DEFAULT_PRIMARY_COLOR && this.uiConfig.theme?.onPrimary === DEFAULT_ON_PRIMARY_COLOR;
246246

247247
if (this.uiConfig?.theme && !isDefaultColors) {
248248
const rootElement = document.getElementById("w3a-parent-container") as HTMLElement;

packages/modal/src/vue/Web3AuthProvider.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export const Web3AuthProvider = defineComponent({
8585

8686
watch(
8787
() => props.config,
88-
(newConfig) => {
88+
(newConfig, _, onInvalidate) => {
8989
const resetHookState = () => {
9090
provider.value = null;
9191
userInfo.value = null;
@@ -94,6 +94,12 @@ export const Web3AuthProvider = defineComponent({
9494
status.value = null;
9595
};
9696

97+
onInvalidate(() => {
98+
if (web3Auth.value) {
99+
web3Auth.value.cleanup();
100+
}
101+
});
102+
97103
resetHookState();
98104
const { web3AuthOptions } = newConfig;
99105
const web3AuthInstance = new Web3Auth(web3AuthOptions);
@@ -105,8 +111,14 @@ export const Web3AuthProvider = defineComponent({
105111
watch(
106112
web3Auth,
107113
async (newWeb3Auth, _, onInvalidate) => {
114+
const controller = new AbortController();
115+
116+
// Invalidate the controller here before calling any async methods.
117+
onInvalidate(() => {
118+
controller.abort();
119+
});
120+
108121
if (newWeb3Auth) {
109-
const controller = new AbortController();
110122
try {
111123
initError.value = null;
112124
isInitializing.value = true;
@@ -116,9 +128,6 @@ export const Web3AuthProvider = defineComponent({
116128
} finally {
117129
isInitializing.value = false;
118130
}
119-
onInvalidate(() => {
120-
controller.abort();
121-
});
122131
}
123132
},
124133
{ immediate: true }

packages/no-modal/src/connectors/auth-connector/authConnector.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,10 @@ class AuthConnector extends BaseConnector<AuthLoginParams> {
306306
public async cleanup(): Promise<void> {
307307
if (!this.authInstance) throw WalletInitializationError.notReady("authInstance is not ready");
308308
await this.authInstance.cleanup();
309+
310+
if (this.wsEmbedInstance) {
311+
this.wsEmbedInstance.clearInit();
312+
}
309313
}
310314

311315
private getChain(chainId: string) {

packages/no-modal/src/vue/no-modal/Web3AuthProvider.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export const Web3AuthProvider = defineComponent({
8585

8686
watch(
8787
() => props.config,
88-
(newConfig) => {
88+
(newConfig, _, onInvalidate) => {
8989
const resetHookState = () => {
9090
provider.value = null;
9191
userInfo.value = null;
@@ -94,6 +94,12 @@ export const Web3AuthProvider = defineComponent({
9494
status.value = null;
9595
};
9696

97+
onInvalidate(() => {
98+
if (web3Auth.value) {
99+
web3Auth.value.cleanup();
100+
}
101+
});
102+
97103
resetHookState();
98104
const { web3AuthOptions } = newConfig;
99105
const web3AuthInstance = new Web3AuthNoModal(web3AuthOptions);
@@ -107,6 +113,12 @@ export const Web3AuthProvider = defineComponent({
107113
async (newWeb3Auth, _, onInvalidate) => {
108114
if (newWeb3Auth) {
109115
const controller = new AbortController();
116+
117+
// Invalidate the controller here before calling any async methods.
118+
onInvalidate(() => {
119+
controller.abort();
120+
});
121+
110122
try {
111123
initError.value = null;
112124
isInitializing.value = true;
@@ -116,10 +128,6 @@ export const Web3AuthProvider = defineComponent({
116128
} finally {
117129
isInitializing.value = false;
118130
}
119-
120-
onInvalidate(() => {
121-
controller.abort();
122-
});
123131
}
124132
},
125133
{ immediate: true }

0 commit comments

Comments
 (0)