Skip to content

Commit

Permalink
fix: loading bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
k0beLeenders authored and chambaz committed Nov 28, 2023
1 parent 5a7d962 commit a52de37
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
39 changes: 20 additions & 19 deletions apps/marginfi-v2-ui/src/components/common/Wallet/WalletButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,27 @@ export const WalletButton = () => {

return (
<>
{!connected ? (
<Button className="gap-1.5 py-0 pr-2">
<div className="flex flex-row relative h-full gap-4">
<div onClick={() => (isLoading ? {} : handleWalletConnect())} className="inline-flex items-center gap-2">
{isLoading || connecting ? "Connecting..." : "Sign in with"}
{walletInfo && <WalletIcon />}
</div>
{walletInfo && (
<div
onClick={() => setIsWalletAuthDialogOpen(true)}
className="pl-2 border-l border-border inline-flex items-center"
>
<IconChevronDown size={20} />
{!isLoading &&
(!connected ? (
<Button className="gap-1.5 py-0 pr-2">
<div className="flex flex-row relative h-full gap-4">
<div onClick={() => handleWalletConnect()} className="inline-flex items-center gap-2">
Sign in with
{walletInfo && <WalletIcon />}
</div>
)}
</div>
</Button>
) : (
<Wallet />
)}
{walletInfo && (
<div
onClick={() => setIsWalletAuthDialogOpen(true)}
className="pl-2 border-l border-border inline-flex items-center"
>
<IconChevronDown size={20} />
</div>
)}
</div>
</Button>
) : (
<Wallet />
))}
</>
);
};
8 changes: 3 additions & 5 deletions apps/marginfi-v2-ui/src/hooks/useWalletContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,7 @@ const WalletProvider = ({ children }: { children: React.ReactNode }) => {
// and override signTransaction methods with web3auth sdk
const makeweb3AuthWalletData = React.useCallback(
async (web3AuthProvider: IProvider) => {
if (!web3Auth) {
setIsLoading(false);
return;
}
if (!web3Auth) return;

const solanaWallet = new SolanaWallet(web3AuthProvider);
const accounts = await solanaWallet.requestAccounts();
Expand Down Expand Up @@ -248,7 +245,6 @@ const WalletProvider = ({ children }: { children: React.ReactNode }) => {
return signedMessage;
},
});
setIsLoading(false);
},
[web3Auth]
);
Expand Down Expand Up @@ -331,6 +327,7 @@ const WalletProvider = ({ children }: { children: React.ReactNode }) => {
if (!web3Auth?.connected || !web3Auth?.provider || web3AuthWalletData) return;
setIsLoading(true);
makeweb3AuthWalletData(web3Auth.provider);
setIsLoading(false);
}, [web3Auth?.connected, web3Auth?.provider, web3AuthWalletData]);

// initialize web3auth sdk on page load
Expand Down Expand Up @@ -361,6 +358,7 @@ const WalletProvider = ({ children }: { children: React.ReactNode }) => {
setweb3Auth(web3AuthInstance);
} catch (error) {
console.error(error);
} finally {
setIsLoading(false);
}
};
Expand Down

0 comments on commit a52de37

Please sign in to comment.