Skip to content

Commit 8e4910b

Browse files
fix: fuels-wallet changed to use fuel react
1 parent 5ceec56 commit 8e4910b

File tree

5 files changed

+59
-70
lines changed

5 files changed

+59
-70
lines changed

examples/react-app/src/components/account.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useDisconnect } from '@fuel-wallet/react';
1+
import { useDisconnect } from '@fuels/react';
22
import Button from './button';
33
import Feature from './feature';
44
import { useWallet } from '../hooks/useWallet';

examples/react-app/src/components/counter.tsx

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import { useEffect, useState } from 'react';
2-
import { useLogEvents } from '../hooks/use-log-events';
3-
import { CounterContractAbi__factory } from '../contracts';
4-
import { DEFAULT_AMOUNT } from './balance';
5-
import Feature from './feature';
6-
import Button from './button';
7-
import Notification, { Props as NotificationProps } from './notification';
8-
import { useWallet } from '../hooks/useWallet';
1+
import { useEffect, useState } from "react";
2+
import { useLogEvents } from "../hooks/use-log-events";
3+
import { CounterContractAbi__factory } from "../contracts";
4+
import { DEFAULT_AMOUNT } from "./balance";
5+
import Feature from "./feature";
6+
import Button from "./button";
7+
import Notification, { Props as NotificationProps } from "./notification";
8+
import { useWallet } from "../hooks/useWallet";
99

1010
export const COUNTER_CONTRACT_ID =
11-
'0x0a46aafb83b387155222893b52ed12e5a4b9d6cd06770786f2b5e4307a63b65c';
11+
"0x0a46aafb83b387155222893b52ed12e5a4b9d6cd06770786f2b5e4307a63b65c";
1212

1313
export default function ContractCounter() {
1414
const { balance, wallet } = useWallet();
1515

16-
const [toast, setToast] = useState<Omit<NotificationProps, 'setOpen'>>({
17-
open: false
16+
const [toast, setToast] = useState<Omit<NotificationProps, "setOpen">>({
17+
open: false,
1818
});
1919

2020
const [isLoading, setLoading] = useState(false);
@@ -61,25 +61,27 @@ export default function ContractCounter() {
6161
setLoading(true);
6262
const contract = CounterContractAbi__factory.connect(
6363
COUNTER_CONTRACT_ID,
64-
wallet
64+
wallet,
6565
);
6666
try {
6767
await contract.functions
6868
.increment()
6969
.txParams({ gasPrice: 1, gasLimit: 100_000 })
7070
.call();
71-
setCounter((prev) => prev + 1);
71+
72+
getCount();
73+
7274
setToast({
7375
open: true,
74-
type: 'success',
75-
children: 'Counter incremented!'
76+
type: "success",
77+
children: "Counter incremented!",
7678
});
7779
} catch (err: any) {
78-
console.error('error sending transaction...', err.message);
80+
console.error("error sending transaction...", err.message);
7981
setToast({
8082
open: true,
81-
type: 'error',
82-
children: `The counter could not be incremented: ${err.message.substring(0, 32)}...`
83+
type: "error",
84+
children: `The counter could not be incremented: ${err.message.substring(0, 32)}...`,
8385
});
8486
} finally {
8587
setLoading(false);
@@ -92,8 +94,9 @@ export default function ContractCounter() {
9294

9395
const counterContract = CounterContractAbi__factory.connect(
9496
COUNTER_CONTRACT_ID,
95-
wallet
97+
wallet,
9698
);
99+
97100
try {
98101
const { value } = await counterContract.functions
99102
.count()

examples/react-app/src/hooks/use-log-events.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { useEffect } from 'react';
2-
import { useFuel } from '@fuel-wallet/react';
1+
import { useEffect } from "react";
2+
import { useFuel } from "@fuels/react";
33

44
export function useLogEvents() {
55
const { fuel } = useFuel();
@@ -8,9 +8,9 @@ export function useLogEvents() {
88
const log = (prefix: string) => (data: unknown) => {
99
console.log(prefix, data);
1010
};
11-
const logAccounts = log('accounts');
12-
const logConnection = log('connection');
13-
const logCurrentAccount = log('currentAccount');
11+
const logAccounts = log("accounts");
12+
const logConnection = log("connection");
13+
const logCurrentAccount = log("currentAccount");
1414

1515
fuel.on(fuel.events.accounts, logAccounts);
1616
fuel.on(fuel.events.connection, logConnection);
Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,62 @@
11
import {
22
useAccounts,
33
useConnectUI,
4-
useConnectors,
54
useIsConnected,
65
useWallet as useFuelWallet,
7-
useBalance
8-
} from '@fuel-wallet/react';
9-
import { useEffect, useState } from 'react';
6+
useBalance,
7+
useFuel,
8+
} from "@fuels/react";
9+
import { useEffect, useState } from "react";
1010

1111
interface ICurrentConnector {
1212
logo: string;
1313
title: string;
1414
}
1515

1616
export const useWallet = () => {
17+
const { fuel } = useFuel();
1718
const { connect, isConnecting } = useConnectUI();
1819
const { isConnected, refetch: refetchConnected } = useIsConnected();
1920
const {
2021
accounts,
2122
isLoading: isLoadingAccounts,
22-
isFetching: isFetchingAccounts
23+
isFetching: isFetchingAccounts,
2324
} = useAccounts();
24-
const {
25-
data,
26-
isLoading: isLoadingConnectors,
27-
isFetching: isFetchingConnectors
28-
} = useConnectors();
2925

3026
const address = accounts[0];
31-
3227
const { wallet, refetch: refetchWallet } = useFuelWallet(address);
28+
3329
const {
3430
balance,
3531
isLoading: isLoadingBalance,
36-
isFetching: isFetchingBalance
32+
isFetching: isFetchingBalance,
3733
} = useBalance({ address });
3834

3935
const [currentConnector, setCurrentConnector] = useState<ICurrentConnector>({
40-
logo: './Fuel_Logo_White_RGB.svg',
41-
title: 'Fuel Wallet Demo'
36+
logo: "",
37+
title: "Fuel Wallet Demo",
4238
});
4339

4440
useEffect(() => {
4541
refetchConnected();
4642
}, [isConnected]);
4743

4844
useEffect(() => {
49-
const connector = data.find(
50-
(connectorData) => connectorData.connected === true
51-
);
45+
const currentConnector = fuel.currentConnector();
5246

53-
let logo =
54-
typeof connector?.metadata.image === 'string'
55-
? connector?.metadata.image
56-
: connector?.metadata.image?.dark ?? './Fuel_Logo_White_RGB.svg';
47+
const title = currentConnector?.name ?? "Fuel Wallet";
5748

58-
const title = connector?.name ?? 'Fuel Wallet';
49+
const logo =
50+
currentConnector && typeof currentConnector.metadata?.image === "object"
51+
? currentConnector.metadata.image.dark ?? ""
52+
: (currentConnector?.metadata?.image as string) ?? "";
5953

6054
setCurrentConnector({ logo, title });
61-
}, [data, isConnected]);
55+
}, [fuel.currentConnector, isConnected]);
6256

63-
const isLoading = [
64-
isLoadingAccounts,
65-
isLoadingConnectors,
66-
isLoadingBalance
67-
].some(Boolean);
57+
const isLoading = [isLoadingAccounts, isLoadingBalance].some(Boolean);
6858

69-
const isFetching = [
70-
isFetchingAccounts,
71-
isFetchingConnectors,
72-
isFetchingBalance
73-
].some(Boolean);
59+
const isFetching = [isFetchingAccounts, isFetchingBalance].some(Boolean);
7460

7561
return {
7662
address,
@@ -84,6 +70,6 @@ export const useWallet = () => {
8470
wallet,
8571
connect,
8672
refetchConnected,
87-
refetchWallet
73+
refetchWallet,
8874
};
8975
};

examples/react-app/src/main.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import React from 'react';
2-
import ReactDOM from 'react-dom/client';
1+
import React from "react";
2+
import ReactDOM from "react-dom/client";
33

4-
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
5-
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
4+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
5+
import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
66

7-
import { FuelProvider } from '@fuel-wallet/react';
8-
import { defaultConnectors } from '@fuels/connectors';
7+
import { FuelProvider } from "@fuels/react";
8+
import { defaultConnectors } from "@fuels/connectors";
99

10-
import * as Toast from '@radix-ui/react-toast';
10+
import * as Toast from "@radix-ui/react-toast";
1111

12-
import App from './App.tsx';
13-
import ScreenSizeIndicator from './components/screensize-indicator.tsx';
14-
import './index.css';
12+
import App from "./App.tsx";
13+
import ScreenSizeIndicator from "./components/screensize-indicator.tsx";
14+
import "./index.css";
1515

1616
const queryClient = new QueryClient();
1717

18-
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
18+
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
1919
<React.StrictMode>
2020
<QueryClientProvider client={queryClient}>
2121
<FuelProvider

0 commit comments

Comments
 (0)