diff --git a/.changeset/tasty-masks-kiss.md b/.changeset/tasty-masks-kiss.md index 935ee122..c33f8c5c 100644 --- a/.changeset/tasty-masks-kiss.md +++ b/.changeset/tasty-masks-kiss.md @@ -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 diff --git a/packages/abstraxion/CHANGELOG.md b/packages/abstraxion/CHANGELOG.md index a5a5c65a..0533a6f8 100644 --- a/packages/abstraxion/CHANGELOG.md +++ b/packages/abstraxion/CHANGELOG.md @@ -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 diff --git a/packages/abstraxion/src/GranteeSignerClient.ts b/packages/abstraxion/src/GranteeSignerClient.ts index 6165c4bf..bd404c09 100644 --- a/packages/abstraxion/src/GranteeSignerClient.ts +++ b/packages/abstraxion/src/GranteeSignerClient.ts @@ -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( @@ -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"); @@ -66,8 +66,8 @@ export class GranteeSignerClient extends SigningCosmWasmClient { fee: StdFee | "auto" | number, memo = "", ): Promise { - // 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 = [ @@ -91,8 +91,8 @@ export class GranteeSignerClient extends SigningCosmWasmClient { memo: string, explicitSignerData?: SignerData, ): Promise { - // 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 = [ diff --git a/packages/abstraxion/src/components/AbstraxionContext/index.tsx b/packages/abstraxion/src/components/AbstraxionContext/index.tsx index 6222f976..94cfd154 100644 --- a/packages/abstraxion/src/components/AbstraxionContext/index.tsx +++ b/packages/abstraxion/src/components/AbstraxionContext/index.tsx @@ -10,8 +10,8 @@ export interface AbstraxionContextProps { setAbstraxionError: React.Dispatch>; abstraxionAccount: DirectSecp256k1HdWallet | undefined; setAbstraxionAccount: React.Dispatch; - grantorAddress: string; - setGrantorAddress: React.Dispatch>; + granterAddress: string; + setgranterAddress: React.Dispatch>; contracts?: string[]; dashboardUrl?: string; } @@ -35,7 +35,7 @@ export const AbstraxionContextProvider = ({ const [abstraxionAccount, setAbstraxionAccount] = useState< DirectSecp256k1HdWallet | undefined >(undefined); - const [grantorAddress, setGrantorAddress] = useState(""); + const [granterAddress, setgranterAddress] = useState(""); return ( { const { isConnected, - grantorAddress, + granterAddress, abstraxionAccount, isConnecting, - setGrantorAddress, + setgranterAddress, setAbstraxionAccount, setIsConnected, setIsConnecting, @@ -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, }; diff --git a/packages/abstraxion/src/hooks/useAbstraxionSigningClient.ts b/packages/abstraxion/src/hooks/useAbstraxionSigningClient.ts index d2e52c4d..e337435f 100644 --- a/packages/abstraxion/src/hooks/useAbstraxionSigningClient.ts +++ b/packages/abstraxion/src/hooks/useAbstraxionSigningClient.ts @@ -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; @@ -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() @@ -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 }; };