Skip to content

Commit

Permalink
feat: add Wallet Connect connector (#61)
Browse files Browse the repository at this point in the history
Co-authored-by: Pedro Pereira <pedro.2108@hotmail.com>
  • Loading branch information
luizstacio and pedropereiradev authored Apr 18, 2024
1 parent eafe351 commit f56bd40
Show file tree
Hide file tree
Showing 31 changed files with 7,525 additions and 595 deletions.
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

1 comment on commit f56bd40

@hulei198819
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am using it, thank you

Please sign in to comment.