Skip to content

Commit

Permalink
add log for signingClient error; replace grantor with granter
Browse files Browse the repository at this point in the history
  • Loading branch information
BurntVal committed Jan 18, 2024
1 parent 30af25a commit f04dd46
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .changeset/tasty-masks-kiss.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"@burnt-labs/abstraxion": minor
---

Add grantee signer client to seamlessly handle grantor/grantee relationships
Add grantee signer client to seamlessly handle granter/grantee relationships
2 changes: 1 addition & 1 deletion packages/abstraxion/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

- [#41](https://github.com/burnt-labs/xion.js/pull/41) [`a269cdf`](https://github.com/burnt-labs/xion.js/commit/a269cdf88722408e91b643d12ce4181ce26296f3) Thanks [@BurntVal](https://github.com/BurntVal)! - abstraxion dynamic url for grant creation on dashboard

- [#44](https://github.com/burnt-labs/xion.js/pull/44) [`56b9f87`](https://github.com/burnt-labs/xion.js/commit/56b9f87482a7210072eaa279960d1ff01ad5b4e0) Thanks [@justinbarry](https://github.com/justinbarry)! - Add grantee signer client to seamlessly handle grantor/grantee relationships
- [#44](https://github.com/burnt-labs/xion.js/pull/44) [`56b9f87`](https://github.com/burnt-labs/xion.js/commit/56b9f87482a7210072eaa279960d1ff01ad5b4e0) Thanks [@justinbarry](https://github.com/justinbarry)! - Add grantee signer client to seamlessly handle granter/grantee relationships

### Patch Changes

Expand Down
20 changes: 10 additions & 10 deletions packages/abstraxion/src/GranteeSignerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import {
} from "@cosmjs/tendermint-rpc";

interface GranteeSignerOptions {
readonly grantorAddress: string;
readonly granterAddress: string;
readonly granteeAddress: string;
}

export class GranteeSignerClient extends SigningCosmWasmClient {
protected readonly grantorAddress: string;
protected readonly granterAddress: string;
protected readonly granteeAddress: string;

public static async connectWithSigner(
Expand All @@ -43,16 +43,16 @@ export class GranteeSignerClient extends SigningCosmWasmClient {
cometClient: TendermintClient | undefined,
signer: OfflineSigner,
{
grantorAddress,
granterAddress,
granteeAddress,
...options
}: SigningCosmWasmClientOptions & GranteeSignerOptions,
) {
super(cometClient, signer, options);
if (grantorAddress === undefined) {
throw new Error("grantorAddress is required");
if (granterAddress === undefined) {
throw new Error("granterAddress is required");
}
this.grantorAddress = grantorAddress;
this.granterAddress = granterAddress;

if (granteeAddress === undefined) {
throw new Error("granteeAddress is required");
Expand All @@ -66,8 +66,8 @@ export class GranteeSignerClient extends SigningCosmWasmClient {
fee: StdFee | "auto" | number,
memo = "",
): Promise<DeliverTxResponse> {
// Figure out if the signerAddress is a grantor
if (signerAddress === this.grantorAddress) {
// Figure out if the signerAddress is a granter
if (signerAddress === this.granterAddress) {
signerAddress = this.granteeAddress;
// Wrap the signerAddress in a MsgExec
messages = [
Expand All @@ -91,8 +91,8 @@ export class GranteeSignerClient extends SigningCosmWasmClient {
memo: string,
explicitSignerData?: SignerData,
): Promise<TxRaw> {
// Figure out if the signerAddress is a grantor
if (signerAddress === this.grantorAddress) {
// Figure out if the signerAddress is a granter
if (signerAddress === this.granterAddress) {
signerAddress = this.granteeAddress;
// Wrap the signerAddress in a MsgExec
messages = [
Expand Down
10 changes: 5 additions & 5 deletions packages/abstraxion/src/components/AbstraxionContext/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export interface AbstraxionContextProps {
setAbstraxionError: React.Dispatch<React.SetStateAction<string>>;
abstraxionAccount: DirectSecp256k1HdWallet | undefined;
setAbstraxionAccount: React.Dispatch<DirectSecp256k1HdWallet | undefined>;
grantorAddress: string;
setGrantorAddress: React.Dispatch<React.SetStateAction<string>>;
granterAddress: string;
setgranterAddress: React.Dispatch<React.SetStateAction<string>>;
contracts?: string[];
dashboardUrl?: string;
}
Expand All @@ -35,7 +35,7 @@ export const AbstraxionContextProvider = ({
const [abstraxionAccount, setAbstraxionAccount] = useState<
DirectSecp256k1HdWallet | undefined
>(undefined);
const [grantorAddress, setGrantorAddress] = useState("");
const [granterAddress, setgranterAddress] = useState("");

return (
<AbstraxionContext.Provider
Expand All @@ -48,8 +48,8 @@ export const AbstraxionContextProvider = ({
setAbstraxionError,
abstraxionAccount,
setAbstraxionAccount,
grantorAddress,
setGrantorAddress,
granterAddress,
setgranterAddress,
contracts,
dashboardUrl,
}}
Expand Down
10 changes: 5 additions & 5 deletions packages/abstraxion/src/components/AbstraxionSignin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ export function AbstraxionSignin(): JSX.Element {
setIsConnecting,
setIsConnected,
setAbstraxionAccount,
setGrantorAddress,
setgranterAddress,
contracts,
dashboardUrl,
} = useContext(AbstraxionContext);

const isMounted = useRef(false);
const [tempAccountAddress, setTempAccountAddress] = useState("");

function configureGrantor(address: string) {
setGrantorAddress(address);
localStorage.setItem("xion-authz-grantor-account", address);
function configuregranter(address: string) {
setgranterAddress(address);
localStorage.setItem("xion-authz-granter-account", address);
}

function openDashboardTab(userAddress: string, contracts?: string[]): void {
Expand Down Expand Up @@ -103,7 +103,7 @@ export function AbstraxionSignin(): JSX.Element {
console.error("More than one granter found. Taking first.");
}

configureGrantor(uniqueGranters[0]);
configuregranter(uniqueGranters[0]);
break;
}
} catch (error) {
Expand Down
6 changes: 3 additions & 3 deletions packages/abstraxion/src/components/Connected/Connected.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import {
} from "../AbstraxionContext";

export function Connected({ onClose }: { onClose: VoidFunction }) {
const { setIsConnected, setAbstraxionAccount, setGrantorAddress } =
const { setIsConnected, setAbstraxionAccount, setgranterAddress } =
useContext(AbstraxionContext) as AbstraxionContextProps;

function handleLogout() {
setIsConnected(false);
localStorage.removeItem("xion-authz-temp-account");
localStorage.removeItem("xion-authz-grantor-account");
localStorage.removeItem("xion-authz-granter-account");
setAbstraxionAccount(undefined);
setGrantorAddress("");
setgranterAddress("");
onClose();
}

Expand Down
24 changes: 12 additions & 12 deletions packages/abstraxion/src/hooks/useAbstraxionAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export interface useAbstraxionAccountProps {
export const useAbstraxionAccount = (): useAbstraxionAccountProps => {
const {
isConnected,
grantorAddress,
granterAddress,
abstraxionAccount,
isConnecting,
setGrantorAddress,
setgranterAddress,
setAbstraxionAccount,
setIsConnected,
setIsConnecting,
Expand All @@ -36,30 +36,30 @@ export const useAbstraxionAccount = (): useAbstraxionAccountProps => {
"abstraxion",
);
setAbstraxionAccount(deserializedKeypair);
const grantorAccount = localStorage.getItem(
"xion-authz-grantor-account",
const granterAccount = localStorage.getItem(
"xion-authz-granter-account",
);
if (grantorAccount) {
setGrantorAddress(grantorAccount);
if (granterAccount) {
setgranterAddress(granterAccount);
setIsConnected(true);
}
} else {
// Wipe grantor even if it exists, clean context
localStorage.removeItem("xion-authz-grantor-account");
// Wipe granter even if it exists, clean context
localStorage.removeItem("xion-authz-granter-account");
setAbstraxionAccount(undefined);
setGrantorAddress("");
setgranterAddress("");
}
setIsConnecting(false);
}

if (!isConnecting && !abstraxionAccount && !grantorAddress) {
if (!isConnecting && !abstraxionAccount && !granterAddress) {
configureAccount();
}
}, [isConnected, abstraxionAccount, grantorAddress]);
}, [isConnected, abstraxionAccount, granterAddress]);

return {
data: {
bech32Address: grantorAddress,
bech32Address: granterAddress,
},
isConnected: isConnected,
};
Expand Down
11 changes: 6 additions & 5 deletions packages/abstraxion/src/hooks/useAbstraxionSigningClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
import { GranteeSignerClient } from "@/src/GranteeSignerClient.ts";

export const useAbstraxionSigningClient = () => {
const { isConnected, abstraxionAccount, grantorAddress } = useContext(
const { isConnected, abstraxionAccount, granterAddress } = useContext(
AbstraxionContext,
) as AbstraxionContextProps;

Expand All @@ -23,8 +23,8 @@ export const useAbstraxionSigningClient = () => {
throw new Error("No account found.");
}

if (!grantorAddress) {
throw new Error("No grantor found.");
if (!granterAddress) {
throw new Error("No granter found.");
}
const granteeAddress = await abstraxionAccount
.getAccounts()
Expand All @@ -40,19 +40,20 @@ export const useAbstraxionSigningClient = () => {
abstraxionAccount,
{
gasPrice: GasPrice.fromString("0uxion"),
grantorAddress,
granterAddress,
granteeAddress,
},
);

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

getSigner();
}, [isConnected, abstraxionAccount, grantorAddress]);
}, [isConnected, abstraxionAccount, granterAddress]);

return { client: abstractClient };
};

0 comments on commit f04dd46

Please sign in to comment.