Skip to content

Commit

Permalink
[PLA-1452] fix loading with connect wallet (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
zlayine authored Nov 28, 2023
1 parent 8042085 commit 8a87ae8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
8 changes: 7 additions & 1 deletion resources/js/components/WalletConnectButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<Menu as="div" class="relative">
<div>
<MenuButton
id="wallet-connect-button"
class="flex items-center space-x-2 rounded-md bg-primary py-2 px-3 text-sm font-semibold shadow-sm focus:outline-none focus:ring-2 focus:ring-primary-light focus:ring-offset-2 text-white transition-all"
>
<WalletIcon class="h-6 w-6" />
Expand All @@ -16,6 +17,7 @@
<template v-if="!walletSession">
<MenuItem v-slot="{ active }">
<button
id="wallet-connect-button__enjin"
:class="[
active ? 'bg-gray-100 text-gray-900' : 'text-gray-700',
'block px-4 py-2 text-sm w-full text-center transition-all',
Expand All @@ -27,6 +29,7 @@
</MenuItem>
<MenuItem v-slot="{ active }">
<button
id="wallet-connect-button__polkadot"
:class="[
active ? 'bg-gray-100 text-gray-900' : 'text-gray-700',
'block px-4 py-2 text-sm w-full text-center transition-all',
Expand All @@ -40,6 +43,7 @@
<template v-else>
<MenuItem v-slot="{ active }">
<button
id="wallet-connect-button__disconnect"
:class="[
active ? 'bg-gray-100 text-gray-900' : 'text-gray-700',
'block px-4 py-2 text-sm w-full text-center transition-all',
Expand Down Expand Up @@ -83,7 +87,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
3 changes: 2 additions & 1 deletion resources/js/components/pages/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
placeholder="Enter token name"
/>
<Btn
id="create-api-token-button"
primary
class="py-2.5 disabled:!bg-primary"
@click="createApiToken"
Expand Down Expand Up @@ -67,7 +68,7 @@
/>
</span>
</div>
<Btn error @click="revokeToken(token.name)">Revoke</Btn>
<Btn :id="`revoke-api-button__${token.name}`" error @click="revokeToken(token.name)">Revoke</Btn>
</div>
</div>
</div>
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 8a87ae8

Please sign in to comment.