Skip to content

Commit

Permalink
fix loading issue
Browse files Browse the repository at this point in the history
  • Loading branch information
zlayine committed Nov 27, 2023
1 parent 8042085 commit 045ca16
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion resources/js/components/WalletConnectButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ const walletSession = computed(() => connectionStore.wallet);
const connectWallet = async (provider: string) => {
try {
loading.value = true;
await connectionStore.connectWallet(provider);
await connectionStore.connectWallet(provider, () => {
loading.value = false;
});
if (connectionStore.accounts) {
showAccountsModal.value = true;
}
Expand Down
12 changes: 9 additions & 3 deletions resources/js/store/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ export const useConnectionStore = defineStore('connection', {
getWeb3Modal() {
return new Web3Modal(walletConnectWeb3modalConfig);
},
async connectWallet(provider) {
async connectWallet(provider: string, endLoading: Function) {
if (provider === 'wc') {
await this.connectWC();
await this.connectWC(endLoading);
}

if (provider === 'polkadot.js') {
Expand Down Expand Up @@ -74,7 +74,7 @@ export const useConnectionStore = defineStore('connection', {
this.walletSession = this.walletClient.session.get(this.walletClient.session.keys[lastKeyIndex]);
}
},
async connectWC() {
async connectWC(endLoading: Function) {
const walletConnect = this.getWeb3Modal();
await this.initWalletClient();

Expand All @@ -86,6 +86,12 @@ export const useConnectionStore = defineStore('connection', {
requiredNamespaces: wcRequiredNamespaces(useAppStore().config.network),
});

walletConnect.subscribeModal(async (event) => {
if (event.open === false) {
endLoading();
}
});

await walletConnect.openModal({
uri,
});
Expand Down

0 comments on commit 045ca16

Please sign in to comment.