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 Wallet Connect connector #61

Merged
merged 44 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
18f4edc
feat: ethereum wallet connector implementation started
pedropereiradev Apr 6, 2024
0bf8d59
feat: connector renamed and all methods implemented
pedropereiradev Apr 7, 2024
fab8817
fix: platform changed to browser
pedropereiradev Apr 7, 2024
ae3c5df
feat: walletconnect connector added to default connectors and evm con…
pedropereiradev Apr 7, 2024
78260be
build: pnpm-lock updated
pedropereiradev Apr 7, 2024
911b465
fix: connect method fixed
pedropereiradev Apr 8, 2024
f98375f
fix: window.ethereum removed as provider
pedropereiradev Apr 8, 2024
c30be18
fix: disconnect method fixed to reload page as walletconnect needs
pedropereiradev Apr 8, 2024
a699b8e
docs: changeset created
pedropereiradev Apr 8, 2024
6def350
test: same tests from evm connector implemented
pedropereiradev Apr 8, 2024
f72d82c
chore: remove unused files
pedropereiradev Apr 9, 2024
3d11378
fix: evm connector added to default connectors again
pedropereiradev Apr 9, 2024
862a85e
fix: window.ethereum removed due conflicts with a dependency
pedropereiradev Apr 9, 2024
c2227ac
refactor: walletconnect connector refactored
pedropereiradev Apr 9, 2024
d494b3b
fix: wallet disconnect and account address inconsistencies fixed
pedropereiradev Apr 9, 2024
517e200
fix: refactor project and fix bugs
pedropereiradev Apr 10, 2024
85766d8
test: ignore tests
pedropereiradev Apr 10, 2024
fc8dc05
build: build process changed
pedropereiradev Apr 10, 2024
ead51c1
fix: removed unrelated code
pedropereiradev Apr 10, 2024
a2d7bf5
fix: restore tsup values
pedropereiradev Apr 10, 2024
4572fc7
test: tests for not implemented methods created
pedropereiradev Apr 10, 2024
ab8e26f
fix: size of connector icon fixed
pedropereiradev Apr 10, 2024
def8168
test: silent console log in tests
pedropereiradev Apr 10, 2024
1c07b47
fix: walletconnect connector icon changed
pedropereiradev Apr 10, 2024
bc4d09b
test: fix warn logs
pedropereiradev Apr 10, 2024
5d5ced1
fix: predicate hashTransaction fixed
pedropereiradev Apr 10, 2024
6d98124
fix: .env ignored
pedropereiradev Apr 11, 2024
a8cd1b4
fix: old connector events removed
pedropereiradev Apr 11, 2024
df9a676
Update examples/react-app/src/main.tsx
pedropereiradev Apr 11, 2024
4968e6f
Merge branch 'feat/ethereum-wallets-connector' of github.com:pedroper…
pedropereiradev Apr 11, 2024
0f6a6a8
fix: query client name changed
pedropereiradev Apr 11, 2024
e0c6910
fix: window.ethereum typed
pedropereiradev Apr 11, 2024
5a5b1ca
test: add test for constructor, account error and network
pedropereiradev Apr 12, 2024
7930e99
feat: add sepolia chain to walletconnect
pedropereiradev Apr 12, 2024
bdc44c0
fix: revert changes in evm-connector
pedropereiradev Apr 12, 2024
eac92a0
Merge branch 'main' into feat/ethereum-wallets-connector
luizstacio Apr 13, 2024
1a67c1a
ci: add specific pnpm version
pedropereiradev Apr 16, 2024
78ec00d
ci: change pnpm-version
pedropereiradev Apr 16, 2024
4191877
chore: merge
luizstacio Apr 18, 2024
b8362f3
chore: remove metamask connector
luizstacio Apr 18, 2024
d02bcda
Merge branch 'main' into pr/43
luizstacio Apr 18, 2024
918a4ad
chore: remove projectId
luizstacio Apr 18, 2024
7dc2424
chore: remove EVM wallet
luizstacio Apr 18, 2024
c70fa94
Merge branch 'pr/43' of github.com:FuelLabs/fuel-connectors into pr/43
luizstacio Apr 18, 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
6 changes: 6 additions & 0 deletions .changeset/eighty-ducks-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-connectors/walletconnect-connector": patch
"@fuels/connectors": patch
---

rename connector name and implement all methods
1 change: 0 additions & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ jobs:
- uses: FuelLabs/github-actions/setups/node@master
with:
pnpm-version: 8.9.0

- run: pnpm audit --prod

lint:
Expand Down
1 change: 1 addition & 0 deletions examples/react-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
2 changes: 2 additions & 0 deletions examples/react-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"@fuels/react": "0.18.1",
"@radix-ui/react-toast": "1.1.5",
"@tanstack/react-query": "5.28.8",
"@wagmi/connectors": "4.1.24",
"@wagmi/core": "2.0.1",
"clsx": "2.1.0",
"fuels": "0.79.0",
"react": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/react-app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function App() {
<img
src={currentConnector.logo}
alt={currentConnector.title}
className="w-20"
className="w-20 h-20"
/>
)}
</div>
Expand Down
54 changes: 52 additions & 2 deletions examples/react-app/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,16 @@ import ReactDOM from 'react-dom/client';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';

import { defaultConnectors } from '@fuels/connectors';
import { coinbaseWallet, walletConnect } from '@wagmi/connectors';
import { http, createConfig, injected } from '@wagmi/core';
import { mainnet, sepolia } from '@wagmi/core/chains';

import {
FuelWalletConnector,
FuelWalletDevelopmentConnector,
FueletWalletConnector,
WalletConnectConnector,
} from '@fuels/connectors';
import { FuelProvider } from '@fuels/react';

import * as Toast from '@radix-ui/react-toast';
Expand All @@ -15,13 +24,54 @@ import './index.css';

const queryClient = new QueryClient();

// ============================================================
// WalletConnect Connector configurations
// https://docs.walletconnect.com/web3modal/javascript/about
// ============================================================
const WC_PROJECT_ID = import.meta.env.VITE_APP_WC_PROJECT_ID;
const METADATA = {
name: 'Wallet Demo',
description: 'Fuel Wallets Demo',
url: location.href,
icons: ['https://connectors.fuel.network/logo_white.png'],
};
const wagmiConfig = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
connectors: [
injected({ shimDisconnect: false }),
walletConnect({
projectId: WC_PROJECT_ID,
metadata: METADATA,
showQrModal: false,
}),
coinbaseWallet({
appName: METADATA.name,
appLogoUrl: METADATA.icons[0],
darkMode: true,
reloadOnDisconnect: true,
}),
],
});

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
<QueryClientProvider client={queryClient}>
<FuelProvider
theme="dark"
fuelConfig={{
connectors: defaultConnectors({ devMode: true }),
connectors: [
new FuelWalletConnector(),
new FueletWalletConnector(),
new WalletConnectConnector({
wagmiConfig,
projectId: WC_PROJECT_ID,
}),
new FuelWalletDevelopmentConnector(),
],
}}
>
<Toast.Provider>
Expand Down
8 changes: 8 additions & 0 deletions examples/react-app/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
/// <reference types="vite/client" />

interface ImportMetaEnv {
readonly VITE_APP_WC_PROJECT_ID: string;
}

interface ImportMeta {
readonly env: ImportMetaEnv;
}
1 change: 1 addition & 0 deletions packages/connectors/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@fuel-connectors/fuel-wallet": "workspace:*",
"@fuel-connectors/fuelet-wallet": "workspace:*",
"@fuel-connectors/evm-connector": "workspace:*",
"@fuel-connectors/walletconnect-connector": "workspace:*",
"@fuel-connectors/burner-wallet-connector": "workspace:*",
"fuels": "0.79.0",
"terser": "5.29.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/connectors/src/defaultConnectors.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BurnerWalletConnector } from '@fuel-connectors/burner-wallet-connector';
import { EVMWalletConnector } from '@fuel-connectors/evm-connector';
import { FuelWalletDevelopmentConnector } from '@fuel-connectors/fuel-development-wallet';
import { FuelWalletConnector } from '@fuel-connectors/fuel-wallet';
import { FueletWalletConnector } from '@fuel-connectors/fuelet-wallet';
import { WalletConnectConnector } from '@fuel-connectors/walletconnect-connector';
import type { FuelConnector } from 'fuels';

type DefaultConnectors = {
Expand All @@ -15,7 +15,7 @@ export function defaultConnectors({
const connectors = [
new FuelWalletConnector(),
new FueletWalletConnector(),
new EVMWalletConnector(),
new WalletConnectConnector(),
new BurnerWalletConnector(),
];

Expand Down
1 change: 1 addition & 0 deletions packages/connectors/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export * from '@fuel-connectors/fuel-development-wallet';
export * from '@fuel-connectors/fuel-wallet';
export * from '@fuel-connectors/fuelet-wallet';
export * from '@fuel-connectors/evm-connector';
export * from '@fuel-connectors/walletconnect-connector';
export * from '@fuel-connectors/burner-wallet-connector';
4 changes: 2 additions & 2 deletions packages/evm-connector/src/EvmWalletConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class EVMWalletConnector extends FuelConnector {
async configProviders(config: EVMWalletConnectorConfig = {}) {
this.config = Object.assign(config, {
fuelProvider: config.fuelProvider || Provider.create(BETA_5_URL),
ethProvider: config.ethProvider || window.ethereum,
ethProvider: config.ethProvider || WINDOW?.ethereum,
});
}

Expand All @@ -77,7 +77,7 @@ export class EVMWalletConnector extends FuelConnector {
setInterval(() => {
if (WINDOW?.ethereum) {
clearInterval(this._ethereumEvents);
window.dispatchEvent(
WINDOW.dispatchEvent(
new CustomEvent('FuelConnector', { detail: this }),
);
}
Expand Down
50 changes: 50 additions & 0 deletions packages/walletconnect-connector/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "@fuel-connectors/walletconnect-connector",
"version": "0.0.1",
"type": "module",
"files": ["dist"],
"main": "./dist/wallet-connector-walletconnect.umd.cjs",
"module": "./dist/wallet-connector-walletconnect.js",
"exports": {
".": {
"import": "./dist/wallet-connector-walletconnect.js",
"require": "./dist/wallet-connector-walletconnect.umd.cjs"
}
},
"types": "./dist/index.d.ts",
"scripts": {
"build:forc": "pnpm fuels-forc build --release --path ./predicate",
"build:resources": "pnpm run build:forc && tsx ./scripts/generatePredicateResources.ts",
"build": "tsup --dts-only",
"build:watch": "pnpm run build:resources && tsup --watch --dts-only",
"ts:check": "tsc --noEmit",
"test": "vitest"
},
"peerDependencies": {
"fuels": ">=0.77.0"
},
"dependencies": {
"@ethereumjs/util": "^9.0.1",
"@ethersproject/bytes": "^5.7.0",
"@wagmi/core": "2.6.15",
"@web3modal/wagmi": "4.1.5",
"memoizee": "^0.4.15",
"viem": "2.9.9"
},
"devDependencies": {
"@fuel-ts/account": "^0.79.0",
"@fuel-ts/forc": "0.79.0",
"@fuel-ts/fuel-core": "^0.79.0",
"@types/memoizee": "^0.4.11",
"fuels": "^0.79.0",
"jsdom": "24.0.0",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"tsup": "8.0.2",
"tsx": "^4.7.0",
"typescript": "5.4.3",
"vite": "^5.0.10",
"vite-plugin-dts": "^3.6.4",
"vitest": "^1.4.0"
}
}
13 changes: 13 additions & 0 deletions packages/walletconnect-connector/predicate/Forc.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[package]]
name = "core"
source = "path+from-root-566CA1D5F8BEAFBF"

[[package]]
name = "predicate"
source = "member"
dependencies = ["std"]

[[package]]
name = "std"
source = "git+https://github.com/fuellabs/sway?tag=v0.49.3#0dc6570377ee9c4a6359ade597fa27351e02a728"
dependencies = ["core"]
5 changes: 5 additions & 0 deletions packages/walletconnect-connector/predicate/Forc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
name = "predicate"
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"types": [
{
"typeId": 0,
"type": "b256",
"components": null,
"typeParameters": null
},
{
"typeId": 1,
"type": "bool",
"components": null,
"typeParameters": null
},
{
"typeId": 2,
"type": "struct EvmAddress",
"components": [
{
"name": "value",
"type": 0,
"typeArguments": null
}
],
"typeParameters": null
},
{
"typeId": 3,
"type": "u64",
"components": null,
"typeParameters": null
}
],
"functions": [
{
"inputs": [
{
"name": "witness_index",
"type": 3,
"typeArguments": null
}
],
"name": "main",
"output": {
"name": "",
"type": 1,
"typeArguments": null
},
"attributes": null
}
],
"loggedTypes": [],
"messagesTypes": [],
"configurables": [
{
"name": "SIGNER",
"configurableType": {
"name": "",
"type": 2,
"typeArguments": []
},
"offset": 1952
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0xad8bfa6ad9c15d9d57af61964c2372ed1fa1ace00aeefbc8ed5cf07192510d68
Binary file not shown.
Loading
Loading