-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add useAbstraxionClient hook to expose a non-signing CosmWasm client
This will unblock apps which wish to make rpc calls before login
- Loading branch information
1 parent
6a1a037
commit dc060e4
Showing
4 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@burnt-labs/abstraxion": minor | ||
--- | ||
|
||
Add a `useAbstraxionClient` hook to expose non-signing client. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { useAbstraxionAccount } from "./useAbstraxionAccount"; | ||
export { useAbstraxionSigningClient } from "./useAbstraxionSigningClient"; | ||
export { useAbstraxionClient } from "./useAbstraxionClient"; | ||
export { useModal } from "./useModal"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { useContext, useEffect, useState } from "react"; | ||
import { testnetChainInfo } from "@burnt-labs/constants"; | ||
import { AbstraxionContext } from "@/src/components/AbstraxionContext"; | ||
import { CosmWasmClient } from "@cosmjs/cosmwasm-stargate"; | ||
|
||
export const useAbstraxionClient = (): { | ||
readonly client: CosmWasmClient | undefined; | ||
} => { | ||
const { rpcUrl } = useContext(AbstraxionContext); | ||
|
||
const [abstractClient, setAbstractClient] = useState< | ||
CosmWasmClient | undefined | ||
>(undefined); | ||
|
||
useEffect(() => { | ||
async function getClient() { | ||
try { | ||
const client = await CosmWasmClient.connect( | ||
// Should be set in the context but defaulting here just in case | ||
rpcUrl || testnetChainInfo.rpc, | ||
); | ||
|
||
setAbstractClient(client); | ||
} catch (error) { | ||
setAbstractClient(undefined); | ||
} | ||
} | ||
|
||
getClient(); | ||
}, [rpcUrl]); | ||
|
||
return { | ||
client: abstractClient, | ||
} as const; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters