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/ethers5 #129

Merged
merged 10 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion apps/native-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@apps/native-cli",
"version": "1.0.3",
"version": "1.0.4",
"private": true,
"scripts": {
"android": "react-native run-android",
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"packages/scaffold-utils",
"packages/scaffold",
"packages/wagmi",
"packages/coinbase",
"packages/coinbase-wagmi",
"packages/coinbase-ethers",
"packages/ethers5",
"apps/*"
],
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions packages/coinbase-ethers/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
lib/
File renamed without changes.
14 changes: 14 additions & 0 deletions packages/coinbase-ethers/bob.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
source: 'src',
output: 'lib',
targets: [
'commonjs',
'module',
[
'typescript',
{
tsc: '../../node_modules/.bin/tsc'
}
]
]
};
62 changes: 62 additions & 0 deletions packages/coinbase-ethers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "@web3modal/coinbase-ethers-react-native",
"version": "1.2.0-canary.1",
"main": "lib/commonjs/index.js",
"types": "lib/typescript/index.d.ts",
"module": "lib/module/index.js",
"source": "src/index.ts",
"scripts": {
"build": "bob build",
"clean": "rm -rf lib",
"test": "jest --passWithNoTests",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
},
"files": [
"src",
"lib"
],
"keywords": [
"web3",
"crypto",
"ethereum",
"web3modal",
"walletconnect",
"react-native",
"coinbase",
"ethers"
],
"repository": "https://github.com/WalletConnect/web3modal-react-native",
"author": "WalletConnect <[email protected]> (https://web3modal.com)",
"homepage": "https://github.com/WalletConnect/web3modal-react-native",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/WalletConnect/web3modal-react-native/issues"
},
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"access": "public"
},
"peerDependencies": {
"@coinbase/wallet-mobile-sdk": ">=1.0.10",
"ethers": ">5 <6"
},
"react-native": "src/index.ts",
"react-native-builder-bob": {
"source": "src",
"output": "lib",
"targets": [
"commonjs",
"module",
[
"typescript",
{
"tsc": "../../node_modules/.bin/tsc"
}
]
]
},
"eslintIgnore": [
"node_modules/",
"lib/"
]
}
File renamed without changes.
72 changes: 72 additions & 0 deletions packages/coinbase-ethers/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { configure, WalletMobileSDKEVMProvider } from '@coinbase/wallet-mobile-sdk';
import type { WalletMobileSDKProviderOptions } from '@coinbase/wallet-mobile-sdk/build/WalletMobileSDKEVMProvider';

interface RequestArguments {
readonly method: string;
readonly params?: readonly unknown[] | object;
}

type CoinbaseProviderOptions = WalletMobileSDKProviderOptions & {
redirect: string;
rpcUrl: string;
};

export class CoinbaseProvider {
private _provider?: WalletMobileSDKEVMProvider;
private _initProviderPromise?: Promise<void>;
private readonly options: CoinbaseProviderOptions;

constructor(options: CoinbaseProviderOptions) {
this.options = options;
this._createProvider();
}

public address = async () => {
return (await this.getProvider()).selectedAddress;
};

public emit = (event: string) => {
this.getProvider().then(provider => provider.emit(event));
};

public on = (event: string, listener: (data: any) => void) => {
this.getProvider().then(provider => provider.on(event, listener));
};

public removeListener = (event: string, listener: (data: any) => void) => {
this.getProvider().then(provider => provider.removeListener(event, listener));
};

public request = async <T>(args: RequestArguments): Promise<T> => {
const provider = await this.getProvider();

return provider.request(args);
};

private async _createProvider() {
if (!this._initProviderPromise) {
this._initProviderPromise = this._initProvider();
}

return this._initProviderPromise;
}

private _initProvider = async () => {
configure({
callbackURL: new URL(this.options.redirect),
hostURL: new URL('https://wallet.coinbase.com/wsegue'), // Don't change -> Coinbase url
hostPackageName: 'org.toshi' // Don't change -> Coinbase wallet scheme
});

this._provider = new WalletMobileSDKEVMProvider({
...this.options,
jsonRpcUrl: this.options.rpcUrl
});
};

public getProvider = async () => {
if (!this._provider) await this._createProvider();

return this._provider!;
};
}
File renamed without changes.
2 changes: 2 additions & 0 deletions packages/coinbase-wagmi/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
lib/
3 changes: 3 additions & 0 deletions packages/coinbase-wagmi/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["../../.eslintrc"]
}
10 changes: 10 additions & 0 deletions packages/coinbase-wagmi/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.log
*.env
npm-debug.log*
node_modules
package-lock.json
src
tests
index.ts
.eslintrc.json
.turbo
14 changes: 14 additions & 0 deletions packages/coinbase-wagmi/bob.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
source: 'src',
output: 'lib',
targets: [
'commonjs',
'module',
[
'typescript',
{
tsc: '../../node_modules/.bin/tsc'
}
]
]
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@web3modal/coinbase-react-native",
"name": "@web3modal/coinbase-wagmi-react-native",
"version": "1.1.1",
"main": "lib/commonjs/index.js",
"types": "lib/typescript/index.d.ts",
Expand All @@ -22,7 +22,8 @@
"web3modal",
"walletconnect",
"react-native",
"coinbase"
"coinbase",
"wagmi"
],
"repository": "https://github.com/WalletConnect/web3modal-react-native",
"author": "WalletConnect <[email protected]> (https://web3modal.com)",
Expand All @@ -36,7 +37,8 @@
"access": "public"
},
"peerDependencies": {
"@coinbase/wallet-mobile-sdk": ">=1.0.10"
"@coinbase/wallet-mobile-sdk": ">=1.0.10",
"wagmi": ">=1 <2"
},
"react-native": "src/index.ts",
"react-native-builder-bob": {
Expand Down
7 changes: 7 additions & 0 deletions packages/coinbase-wagmi/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#### 🔎 [Examples](https://github.com/WalletConnect/react-native-examples)

#### 🔗 [Website](https://web3modal.com)

# Web3Modal

Your on-ramp to web3 multichain. Web3Modal is a versatile library that makes it super easy to connect users with your Dapp and start interacting with the blockchain.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import type { WalletMobileSDKProviderOptions } from '@coinbase/wallet-mobile-sdk
const ADD_ETH_CHAIN_METHOD = 'wallet_addEthereumChain';
const SWITCH_ETH_CHAIN_METHOD = 'wallet_switchEthereumChain';

type CoinbaseWagmiConnectorOptions = WalletMobileSDKProviderOptions & {
type CoinbaseConnectorOptions = WalletMobileSDKProviderOptions & {
redirect: string;
};

export class CoinbaseWagmiConnector extends Connector<
export class CoinbaseConnector extends Connector<
WalletMobileSDKEVMProvider,
CoinbaseWagmiConnectorOptions
CoinbaseConnectorOptions
> {
readonly id = 'coinbaseWallet';
readonly name = 'Coinbase Wallet';
Expand All @@ -31,7 +31,7 @@ export class CoinbaseWagmiConnector extends Connector<
private _provider?: WalletMobileSDKEVMProvider;
private _initProviderPromise?: Promise<void>;

constructor(config: { chains?: Chain[]; options: CoinbaseWagmiConnectorOptions }) {
constructor(config: { chains?: Chain[]; options: CoinbaseConnectorOptions }) {
super(config);
this._createProvider();
}
Expand Down
5 changes: 5 additions & 0 deletions packages/coinbase-wagmi/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../../tsconfig.json",
"include": ["src"],
"exclude": ["lib", "node_modules"]
}
26 changes: 0 additions & 26 deletions packages/coinbase/CHANGELOG.md

This file was deleted.

2 changes: 0 additions & 2 deletions packages/coinbase/src/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/core/src/utils/CoreHelperUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const CoreHelperUtil = {
}
}

return formattedBalance ? `${formattedBalance} ${symbol}` : '0.000';
return formattedBalance ? `${formattedBalance} ${symbol}` : `0.000 ${symbol || ''}`;
},

isRestrictedRegion() {
Expand Down
2 changes: 2 additions & 0 deletions packages/ethers5/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
lib/
3 changes: 3 additions & 0 deletions packages/ethers5/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["../../.eslintrc"]
}
10 changes: 10 additions & 0 deletions packages/ethers5/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.log
*.env
npm-debug.log*
node_modules
package-lock.json
src
tests
index.ts
.eslintrc.json
.turbo
14 changes: 14 additions & 0 deletions packages/ethers5/bob.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
source: 'src',
output: 'lib',
targets: [
'commonjs',
'module',
[
'typescript',
{
tsc: '../../node_modules/.bin/tsc'
}
]
]
};
Loading
Loading