-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: sdk tweaks and add to walletd
- Loading branch information
1 parent
815ef68
commit d26a952
Showing
19 changed files
with
126 additions
and
58 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 @@ | ||
--- | ||
'@siafoundation/sdk': minor | ||
--- | ||
|
||
signTransaction has been updated to the more specific signTransactionV1. |
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 @@ | ||
--- | ||
'@siafoundation/sdk': minor | ||
--- | ||
|
||
WebTransportClient no longer requires the SDK API as an explicit constructor parameter. |
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
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
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
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
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,27 @@ | ||
import { createContext, useContext, useEffect } from 'react' | ||
import { initSDK } from '@siafoundation/sdk' | ||
|
||
function useAppMain() { | ||
// Initialize the SDK on app load | ||
useEffect(() => { | ||
const func = async () => { | ||
await initSDK() | ||
} | ||
func() | ||
}, []) | ||
return {} | ||
} | ||
|
||
type State = ReturnType<typeof useAppMain> | ||
|
||
const AppContext = createContext({} as State) | ||
export const useApp = () => useContext(AppContext) | ||
|
||
type Props = { | ||
children: React.ReactNode | ||
} | ||
|
||
export function AppProvider({ children }: Props) { | ||
const state = useAppMain() | ||
return <AppContext.Provider value={state}>{children}</AppContext.Provider> | ||
} |
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
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
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,2 +1,4 @@ | ||
export * from './init' | ||
export * from './types' | ||
export { initSDK } from './init' | ||
export { getSDK } from './sdk' | ||
export type { SDK } from './sdk' |
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,12 +1,22 @@ | ||
import { WebTransportClient } from './transport' | ||
import { WASM } from './types' | ||
import { WasmApi } from './types' | ||
|
||
export function getSDK() { | ||
export type SDK = WasmApi & { | ||
WebTransportClient: typeof WebTransportClient | ||
} | ||
|
||
export function getWasmApi(): WasmApi { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const wasm = (global as any).sia as WASM | ||
return (globalThis as any).sia as WasmApi | ||
} | ||
|
||
export function getSDK(): SDK { | ||
const wasmApi = getWasmApi() | ||
if (wasmApi === undefined) { | ||
throw new Error('The Sia SDK has not been initialized') | ||
} | ||
return { | ||
rhp: wasm.rhp, | ||
wallet: wasm.wallet, | ||
...wasmApi, | ||
WebTransportClient, | ||
} | ||
} |
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
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
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
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
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
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
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
Oops, something went wrong.