Skip to content

Commit

Permalink
abstraxion logic fix on connect (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntVal authored May 2, 2024
1 parent f018dc1 commit 210bac1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-rice-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@burnt-labs/abstraxion": minor
---

Fix connect/login logic
23 changes: 13 additions & 10 deletions packages/abstraxion/src/components/AbstraxionSignin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ export function AbstraxionSignin(): JSX.Element {
});
const data = (await res.json()) as GrantsResponse;
if (data.grants.length > 0) {
configuregranter(granter);
// Remove query parameter "granted" and "granter"
const currentUrl = new URL(window.location.href);
currentUrl.searchParams.delete("granted");
Expand Down Expand Up @@ -184,25 +183,29 @@ export function AbstraxionSignin(): JSX.Element {
} else {
keypair = await generateAndStoreTempAccount();
}

const existingGranter = localStorage.getItem(
"xion-authz-granter-account",
);
const searchParams = new URLSearchParams(window.location.search);
const isGranted = searchParams.get("granted");
const granter = searchParams.get("granter");
const granter = existingGranter || searchParams.get("granter");
const accounts = await keypair.getAccounts();
const address = accounts[0].address;
setTempAccountAddress(address);

if (!isGranted && !granterAddress) {
const { dashboardUrl } = await fetchConfig(rpcUrl);
setDashboardUrl(dashboardUrl);
openDashboardTab(address, contracts, dashboardUrl);
} else if (isGranted && !granterAddress) {
if (existingKeypair && granter) {
await pollForGrants(address, granter);
setIsConnecting(false);
setIsConnected(true);
setShowModal(false);
setAbstraxionAccount(keypair);
} else {
setIsConnected(true);
configuregranter(granter);
} else if (existingKeypair && !granter) {
await generateAndStoreTempAccount(); // just replace existing keypair
localStorage.removeItem("xion-authz-granter-account"); // just in case
const { dashboardUrl } = await fetchConfig(rpcUrl);
setDashboardUrl(dashboardUrl);
openDashboardTab(address, contracts, dashboardUrl);
}
} catch (error) {
console.log("Something went wrong: ", error);
Expand Down
2 changes: 1 addition & 1 deletion packages/abstraxion/src/hooks/useAbstraxionAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const useAbstraxionAccount = (): AbstraxionAccountState => {
setIsConnecting(false);
}

if (!isConnecting && !abstraxionAccount && !granterAddress) {
if ((!isConnecting && !abstraxionAccount) || !granterAddress) {
configureAccount();
}
}, [isConnected, abstraxionAccount, granterAddress]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export const useAbstraxionSigningClient = (): {

setAbstractClient(directClient);
} catch (error) {
console.log("Something went wrong: ", error);
setAbstractClient(undefined);
}
}
Expand Down

0 comments on commit 210bac1

Please sign in to comment.