-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7533fae
commit 1f7767f
Showing
58 changed files
with
489 additions
and
265 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,7 @@ | ||
--- | ||
'@fuel-wallet/sdk': minor | ||
--- | ||
|
||
feat: add hooks `useAddAssets`, `useAddNetwork`, `useAssets` and `useNetwork`. | ||
feat: improve hooks `useWallet` `useConnect` and `useAccounts`. | ||
feat: remove `FuelConnectorProvider` and consolidate into `FuelProvider`. |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,7 @@ | ||
import { useConnectors, useFuelConnect } from '@fuel-wallet/react'; | ||
import { useConnectUI } from '@fuel-wallet/react'; | ||
|
||
export const Header = () => { | ||
const { connect } = useFuelConnect(); | ||
const { connectors } = useConnectors(); | ||
const { connect } = useConnectUI(); | ||
|
||
return ( | ||
<button disabled={!connectors.length} onClick={connect}> | ||
Connect | ||
</button> | ||
); | ||
return <button onClick={connect}>Connect</button>; | ||
}; |
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,14 +1,10 @@ | ||
import { FuelProvider, FuelConnectProvider } from '@fuel-wallet/react'; | ||
import { FuelProvider } from '@fuel-wallet/react'; | ||
import type { ReactNode } from 'react'; | ||
|
||
type ProviderProps = { | ||
children: ReactNode; | ||
}; | ||
|
||
export const Providers = ({ children }: ProviderProps) => { | ||
return ( | ||
<FuelProvider> | ||
<FuelConnectProvider>{children}</FuelConnectProvider> | ||
</FuelProvider> | ||
); | ||
return <FuelProvider>{children}</FuelProvider>; | ||
}; |
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,25 @@ | ||
import type { Asset } from '@fuel-wallet/sdk'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
|
||
import { useFuel } from '../providers'; | ||
import { MUTATION_KEYS } from '../utils'; | ||
|
||
export const useAddAssets = () => { | ||
const { fuel } = useFuel(); | ||
|
||
const { mutate, mutateAsync, ...queryProps } = useMutation( | ||
[MUTATION_KEYS.addAssets], | ||
async (assets: Asset | Asset[]) => { | ||
if (Array.isArray(assets)) { | ||
return fuel.addAssets(assets); | ||
} | ||
return fuel.addAsset(assets); | ||
} | ||
); | ||
|
||
return { | ||
addAssets: (assets: Asset | Asset[]) => mutate(assets), | ||
addAssetsAsync: (assets: Asset | Asset[]) => mutateAsync(assets), | ||
...queryProps, | ||
}; | ||
}; |
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,21 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
|
||
import { useFuel } from '../providers'; | ||
import { MUTATION_KEYS } from '../utils'; | ||
|
||
export const useAddNetwork = () => { | ||
const { fuel } = useFuel(); | ||
|
||
const { mutate, mutateAsync, ...queryProps } = useMutation( | ||
[MUTATION_KEYS.addAssets], | ||
async (networkUrl: string) => { | ||
return fuel.addNetwork(networkUrl); | ||
} | ||
); | ||
|
||
return { | ||
addNetwork: (networkUrl: string) => mutate(networkUrl), | ||
addNetworkAsync: (networkUrl: string) => mutateAsync(networkUrl), | ||
...queryProps, | ||
}; | ||
}; |
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,29 @@ | ||
import type { Asset } from '@fuel-wallet/sdk'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import { useFuel } from '../providers'; | ||
import { QUERY_KEYS } from '../utils'; | ||
|
||
export const useAssets = () => { | ||
const { fuel } = useFuel(); | ||
|
||
const { data, ...queryProps } = useQuery( | ||
[QUERY_KEYS.assets], | ||
async () => { | ||
try { | ||
const assets = (await fuel.assets()) as Array<Asset>; | ||
return assets || []; | ||
} catch (error: unknown) { | ||
return []; | ||
} | ||
}, | ||
{ | ||
initialData: [], | ||
} | ||
); | ||
|
||
return { | ||
assets: data, | ||
...queryProps, | ||
}; | ||
}; |
Oops, something went wrong.