Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add/select network flow #1468

Merged
merged 47 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
73f3329
feat: bump @fuels/connectors
helciofranco Sep 10, 2024
446d5a5
chore: add network button
helciofranco Sep 10, 2024
4e49f06
Merge branch 'master' of github.com:FuelLabs/fuels-wallet into hf/fea…
helciofranco Sep 10, 2024
259a56d
Revert "feat: bump @fuels/connectors"
helciofranco Sep 10, 2024
8bdf3aa
chore: bump @fuels/react and @fuels/connectors in the dapp
helciofranco Sep 10, 2024
f6e84b0
chore: add switch network button
helciofranco Sep 10, 2024
bed9c52
feat: allow user to switch to a network
helciofranco Sep 10, 2024
80ab6b1
chore: fire promises for add network
helciofranco Sep 10, 2024
d151406
chore: remove unnecessary spread operator
helciofranco Sep 10, 2024
35fa4ad
feat: add switch terms
helciofranco Sep 10, 2024
cca82f2
docs: add changeset
helciofranco Sep 10, 2024
da26aba
Merge branch 'master' into hf/feat/add-switch-network-experience
helciofranco Sep 10, 2024
a61aaee
feat: add networks to the background service
helciofranco Sep 11, 2024
612e8b5
feat: add select network flow
helciofranco Sep 12, 2024
7f63fe3
Merge branch 'hf/feat/add-switch-network-experience' of github.com:Fu…
helciofranco Sep 12, 2024
4d49d71
chore: replace switch terms with select
helciofranco Sep 12, 2024
bb57121
feat: add an example with deprecated add network
helciofranco Sep 12, 2024
307d499
Merge branch 'master' of github.com:FuelLabs/fuels-wallet into hf/fea…
helciofranco Sep 13, 2024
b3d540c
feat: add a way to select network using chain id and/or url
helciofranco Sep 13, 2024
fe77625
fix: adjust network unit tests
helciofranco Sep 13, 2024
88ccda3
chore: refresh lockfile
helciofranco Sep 13, 2024
6a57d91
fix: add missing type
helciofranco Sep 13, 2024
1e0dca7
feat: bump everything to the latest sdk and connectors
helciofranco Sep 13, 2024
f91c12c
docs: update the changeset to be single line
helciofranco Sep 13, 2024
9224fa9
fix: save with chain id
helciofranco Sep 13, 2024
a01699a
feat: add loading state to the select network popup
helciofranco Sep 13, 2024
a34fd00
feat: add minimal loading state to the examples
helciofranco Sep 13, 2024
8d8e160
feat: allow to select the network when available
helciofranco Sep 13, 2024
5972cc2
chore: adjust examples
helciofranco Sep 13, 2024
220240f
feat: add error state when selecting a network
helciofranco Sep 13, 2024
35b747a
feat: bump @fuels/connectors to 0.28.0
helciofranco Sep 13, 2024
d1f9d5d
feat: get chain ids from the sdk
helciofranco Sep 13, 2024
777d3b8
feat: validate network before opening the popup
helciofranco Sep 14, 2024
a5c67a0
feat: add a special layout when selecting a different network
helciofranco Sep 14, 2024
8c4a99d
feat: add switch using devnet url
helciofranco Sep 14, 2024
51497a7
chore: revert unsafe workaround
helciofranco Sep 14, 2024
8bbfbd5
chore: adjust migration
helciofranco Sep 14, 2024
6388d59
chore: revert changeset
helciofranco Sep 14, 2024
94233e2
chore: changeset
helciofranco Sep 14, 2024
347a56f
chore: increase opacity
helciofranco Sep 14, 2024
69444ea
chore: reword to switch
helciofranco Sep 14, 2024
eefa9c5
test: pass all needed data even when adding network
helciofranco Sep 14, 2024
4badb08
test: add select network e2e
helciofranco Sep 14, 2024
3457119
test: skip a e2e test about the select network
helciofranco Sep 16, 2024
faa86fa
Merge branch 'master' of github.com:FuelLabs/fuels-wallet into hf/fea…
helciofranco Sep 16, 2024
70107c4
test: skip a e2e test about the select network
helciofranco Sep 16, 2024
7fdb949
Merge branch 'master' of github.com:FuelLabs/fuels-wallet into hf/fea…
helciofranco Sep 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tough-bobcats-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fuels-wallet": minor
---

Allow users to switch to or create a network through the `selectNetwork` flow, selecting it if it already exists or creating it if not.
6 changes: 3 additions & 3 deletions examples/cra-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"start": "vite"
},
"dependencies": {
"@fuels/connectors": "0.25.0",
"@fuels/react": "0.25.0",
"@fuels/connectors": "0.28.0",
"@fuels/react": "0.28.0",
"@tanstack/react-query": "5.28.4",
"fuels": "0.94.4",
"fuels": "0.94.6",
"react": "18.3.1",
"react-dom": "18.3.1"
},
Expand Down
5 changes: 5 additions & 0 deletions examples/cra-dapp/src/App.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
body {
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
font-size: 14px;
}

.App {
display: flex;
flex-direction: column;
Expand Down
110 changes: 21 additions & 89 deletions examples/cra-dapp/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,101 +1,33 @@
import {
useAccount,
useAccounts,
useConnectUI,
useDisconnect,
useFuel,
useIsConnected,
useWallet,
} from '@fuels/react';
import { useConnectUI, useIsConnected } from '@fuels/react';
import { Connected } from './Connected';

import { bn } from 'fuels';
import './App.css';

function App() {
const { connect, error, isError, theme, isConnecting } = useConnectUI();
const { connect, theme, isConnecting } = useConnectUI();

const { fuel } = useFuel();
const { disconnect } = useDisconnect();
const { isConnected } = useIsConnected();
const { wallet } = useWallet();
const { account } = useAccount();
const { accounts } = useAccounts();

return (
<div className="App" data-theme={theme}>
<div className="Actions">
<button
type="button"
onClick={() => {
console.log('connect');
connect();
}}
>
{isConnecting ? 'Connecting' : 'Connect'}
</button>
{isConnected && (
<button type="button" onClick={() => disconnect()}>
Disconnect
if (!isConnected) {
return (
<div className="App" data-theme={theme}>
<div className="Actions">
<button
type="button"
onClick={() => {
connect();
}}
>
{isConnecting ? 'Connecting' : 'Connect'}
</button>
)}
<button
type="button"
onClick={async () => {
const txn = await wallet?.createTransfer(
'0xed73857a06ba2a706700e4e69e59f63a012ae6663a54309043e8fdc690bed926',
bn(100),
undefined,
{
tip: bn(2000),
}
);

if (!txn || !account) return;

try {
const result = await fuel.sendTransaction(account, txn);
console.log(result);
} catch (e) {
console.error(e);
}
}}
>
Send transaction with custom fees
</button>
<button
type="button"
onClick={async () => {
const txn = await wallet?.createTransfer(
'0xed73857a06ba2a706700e4e69e59f63a012ae6663a54309043e8fdc690bed926',
bn(100),
undefined,
undefined
);

if (!txn || !account) return;

try {
const result = await fuel.sendTransaction(account, txn);
console.log(result);
} catch (e) {
console.error(e);
}
}}
>
Send transaction with default fees
</button>
</div>
{isError && <p className="Error">{error?.message}</p>}
{isConnected && (
<div className="Accounts">
<h3>Connected accounts</h3>
{accounts?.map((account) => (
<div key={account}>
<b>Account:</b> {account}
</div>
))}
</div>
)}
</div>
);
}

return (
<div className="App" data-theme={theme}>
<Connected />
</div>
);
}
Expand Down
192 changes: 192 additions & 0 deletions examples/cra-dapp/src/Connected.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import {
useAccount,
useAccounts,
useAddNetwork,
useDisconnect,
useFuel,
useNetwork,
useNetworks,
useSelectNetwork,
useWallet,
} from '@fuels/react';

import { DEVNET_NETWORK_URL, TESTNET_NETWORK_URL, bn } from 'fuels';
import './App.css';

export function Connected() {
const { fuel } = useFuel();
const { disconnect } = useDisconnect();
const { wallet } = useWallet();
const { account } = useAccount();
const { accounts } = useAccounts();

const { network } = useNetwork();
const { networks } = useNetworks();
const { selectNetworkAsync, isPending: isSelectingNetwork } =
useSelectNetwork();

const { addNetworkAsync, isPending: isAddingNetwork } = useAddNetwork();

return (
<div>
<div className="Actions">
<button type="button" onClick={() => disconnect()}>
Disconnect
</button>
<button
type="button"
onClick={async () => {
const txn = await wallet?.createTransfer(
'0xed73857a06ba2a706700e4e69e59f63a012ae6663a54309043e8fdc690bed926',
bn(100),
undefined,
{
tip: bn(2000),
}
);

if (!txn || !account) return;

try {
const result = await fuel.sendTransaction(account, txn);
console.log(result);
} catch (e) {
console.error(e);
}
}}
>
Send transaction with custom fees
</button>
<button
type="button"
onClick={async () => {
const txn = await wallet?.createTransfer(
'0xed73857a06ba2a706700e4e69e59f63a012ae6663a54309043e8fdc690bed926',
bn(100),
undefined,
undefined
);

if (!txn || !account) return;

try {
const result = await fuel.sendTransaction(account, txn);
console.log(result);
} catch (e) {
console.error(e);
}
}}
>
Send transaction with default fees
</button>
</div>

<br />
<br />

<div className="Actions">
<button
type="button"
onClick={async () => {
try {
const res = await selectNetworkAsync({
chainId: 0,
});
console.log(res);
} catch (e) {
console.error(e);
}
}}
>
{isSelectingNetwork ? 'Loading...' : 'Select chainId 0'}
</button>
<button
type="button"
onClick={async () => {
try {
const res = await selectNetworkAsync({
url: DEVNET_NETWORK_URL,
});
console.log(res);
} catch (e) {
console.error(e);
}
}}
>
{isSelectingNetwork ? 'Loading...' : 'Select Devnet by URL'}
</button>
<button
type="button"
onClick={async () => {
try {
const res = await selectNetworkAsync({
url: TESTNET_NETWORK_URL,
});
console.log(res);
} catch (e) {
console.error(e);
}
}}
>
{isSelectingNetwork ? 'Loading...' : 'Select Testnet by URL'}
</button>
<button
type="button"
onClick={async () => {
try {
const res = await selectNetworkAsync({
chainId: 111,
});
console.log(res);
} catch (e) {
console.error(e);
}
}}
>
{isSelectingNetwork ? 'Loading...' : 'Select Unknown ChainId'}
</button>

<button
type="button"
onClick={async () => {
try {
const res = await addNetworkAsync(TESTNET_NETWORK_URL);
console.log(res);
} catch (e) {
console.error(e);
}
}}
>
{isAddingNetwork ? 'Loading...' : 'Add testnet'}
</button>
</div>

<div className="Accounts">
<h3>Current Network</h3>
<div>
<b>Chain Id:</b> {network?.chainId?.toString()}
</div>
<div>
<b>Url:</b> {network?.url}
</div>
</div>

<div className="Accounts">
<h3>Connected accounts</h3>
{accounts?.map((account) => (
<div key={account}>
<b>Account:</b> {account}
</div>
))}
</div>
<div className="Accounts">
<h3>Networks</h3>
{networks?.map((network) => (
<div key={network.url}>
<b>{network.chainId}:</b> {network.url}
</div>
))}
</div>
</div>
);
}
4 changes: 2 additions & 2 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "fuels-wallet",
"private": true,
"version": "0.27.4",
"database": "18",
"database": "19",
"scripts": {
"build:all": "run-s build:web build:crx build:storybook",
"build:web": "./scripts/build.sh --app=vite",
Expand Down Expand Up @@ -45,7 +45,7 @@
"events": "3.3.0",
"fake-indexeddb": "4.0.2",
"framer-motion": "10.16.4",
"fuels": "0.94.4",
"fuels": "0.94.6",
"json-edit-react": "1.13.3",
"json-rpc-2.0": "1.7.0",
"lodash.debounce": "4.0.8",
Expand Down
Loading
Loading