Skip to content

Commit

Permalink
abstraxion logic fix on connect
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntVal committed May 2, 2024
1 parent f018dc1 commit dc781a3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
20 changes: 11 additions & 9 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,28 @@ 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 (keypair && granter) {
await pollForGrants(address, granter);
setIsConnecting(false);
setIsConnected(true);
setShowModal(false);
setAbstraxionAccount(keypair);
configuregranter(granter);
} else {
setIsConnected(true);
await generateAndStoreTempAccount(); // just replace existing keypair
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 dc781a3

Please sign in to comment.