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

Ethereum wallets selector. #1106

Merged
merged 47 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
2c61d49
feat: Ethereum wallets mvp.
paouvrard Apr 24, 2024
8461c0b
feat: Relayer onboarding.
paouvrard May 3, 2024
0c468be
fix: Use near_getPublicKey api.
paouvrard May 8, 2024
8391e5b
feat: Get receipt and txStatus.
paouvrard May 14, 2024
16b5927
fix: Remove RLP_EXECUTE check.
paouvrard May 15, 2024
cee568b
fix: Handling of network switch from wallet.
paouvrard May 15, 2024
28b2468
style: Update logo.
paouvrard May 15, 2024
9a0a901
fix: Re-apply rlp_execute limitation to relayer key.
paouvrard May 15, 2024
fc18d7c
build: Upgrade web3Modal, add WC example.
paouvrard May 16, 2024
6c137e1
feat: Query estimateGas (also fixes MetaMask mobile).
paouvrard May 20, 2024
07705d4
fix: Improve modal text.
paouvrard May 21, 2024
27540ee
style: Modal lint.
paouvrard May 21, 2024
7a6c373
fix: Improve onboarding text.
paouvrard May 22, 2024
d26fbb0
feat: Parse error from NEAR transaction.
paouvrard May 23, 2024
d2a0f3e
build: Update assets ethereum-wallets-icon.png.
paouvrard May 27, 2024
73aff7a
feat: Network not supported error message.
paouvrard May 27, 2024
a52e7e2
feat: Optional wagmiCore param and dynamic import.
paouvrard May 27, 2024
396fab0
fix: Dynamic import on page reload.
paouvrard May 28, 2024
ec044bb
Add modal styling (#5)
santerisarle May 29, 2024
4deef6f
refactor: Remove rpcUrl param, get explorer url from wagmiConfig.
paouvrard May 29, 2024
ccb803d
chore: Improve docs.
paouvrard May 29, 2024
34608cd
build: Fix lint.
paouvrard May 29, 2024
ab88d31
More design (#6)
santerisarle May 31, 2024
f141026
style: Tweak text.
paouvrard May 31, 2024
72abcca
fix: Custom chainId.
paouvrard Jun 5, 2024
ab2bed4
style: Hide yocto deposit.
paouvrard Jun 5, 2024
5e8a9af
fix: Improve NEAR tx error parsing.
paouvrard Jun 13, 2024
e2e738b
feat: Add alwaysOnboardDuringSignIn option.
paouvrard Jun 20, 2024
104bec4
fix: Improve error handling during signIn.
paouvrard Jun 21, 2024
35841f8
feat: Log in with Ethereum flow.
paouvrard Jun 24, 2024
1fea570
fix: Check isConnecting state.
paouvrard Jun 24, 2024
447254b
docs: Log in with Ethereum flow.
paouvrard Jun 24, 2024
fb701d0
feat: Web3Modal is optional, default to injected wallet.
paouvrard Jun 25, 2024
9a984a1
fix: Wait for missing txStatus and receipt.
paouvrard Jun 26, 2024
bc9203a
fix: Handle alternative error message.
paouvrard Jun 26, 2024
34d0f82
fix: Tweak log in with Ethereum flow.
paouvrard Jun 26, 2024
a727916
fix: Disconnect wallet when switch to account without LAK.
paouvrard Jun 26, 2024
8c93268
fix: Use wagmi.simulateContract.
paouvrard Jun 28, 2024
35e85a1
feat: Confirm action and allow retry. (#11)
paouvrard Jul 1, 2024
a40b498
fix: Hide Web3Modal after signIn.
paouvrard Jul 1, 2024
d8e4619
chore: Rename.
paouvrard Jul 1, 2024
3348741
feat: 1wei free onboarding.
paouvrard Jul 10, 2024
d1967c1
Merge branch 'dev' into ethereum-wallets
paouvrard Jul 16, 2024
71533ff
build: Upgrade Ethereum dependencies.
paouvrard Jul 16, 2024
4574982
Merge branch 'dev' into ethereum-wallets
paouvrard Jul 25, 2024
2221a62
build: Fix Angular.
paouvrard Jul 25, 2024
6a4757d
feat: Chain switch modal. (#13)
paouvrard Jul 25, 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
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
"eslint.format.enable": true,
"prettier.enable": false,
"editor.codeActionsOnSave": {
"source.fixAll.eslint":
true
"source.fixAll.eslint": "explicit"
},
"typescript.tsdk": "node_modules/typescript/lib"
}
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ NEAR Wallet Selector makes it easy for users to interact with your dApp by provi
- [NearFi Wallet](https://www.npmjs.com/package/@near-wallet-selector/nearfi) - Mobile wallet.
- [Near Mobile Wallet](https://www.npmjs.com/package/@near-wallet-selector/near-mobile-wallet) - Mobile Wallet.
- [WalletConnect](https://www.npmjs.com/package/@near-wallet-selector/wallet-connect) - Bridge wallet.
- [Ethereum wallets](https://www.npmjs.com/package/@near-wallet-selector/ethereum-wallets) - Injected wallet.

## Preview

Expand Down Expand Up @@ -72,6 +73,7 @@ yarn add \
@near-wallet-selector/ramper-wallet \
@near-wallet-selector/near-mobile-wallet \
@near-wallet-selector/mintbase-wallet
@near-wallet-selector/ethereum-wallets

# Using NPM.
npm install \
Expand All @@ -94,6 +96,7 @@ npm install \
@near-wallet-selector/ramper-wallet \
@near-wallet-selector/near-mobile-wallet \
@near-wallet-selector/mintbase-wallet
@near-wallet-selector/ethereum-wallets
```

Optionally, you can install our [`modal-ui`](https://www.npmjs.com/package/@near-wallet-selector/modal-ui) or [`modal-ui-js`](https://www.npmjs.com/package/@near-wallet-selector/modal-ui-js) package for a pre-built interface that wraps the `core` API and presents the supported wallets:
Expand Down Expand Up @@ -131,6 +134,7 @@ import { setupXDEFI } from "@near-wallet-selector/xdefi";
import { setupRamperWallet } from "@near-wallet-selector/ramper-wallet";
import { setupNearMobileWallet } from "@near-wallet-selector/near-mobile-wallet";
import { setupMintbaseWallet } from "@near-wallet-selector/mintbase-wallet";
import { setupEthereumWallets } from "@near-wallet-selector/ethereum-wallets";

const selector = await setupWalletSelector({
network: "testnet",
Expand Down Expand Up @@ -166,6 +170,7 @@ const selector = await setupWalletSelector({
callbackUrl: "https://www.mywebsite.com",
deprecated: false,
}),
setupEthereumWallets({ wagmiConfig, web3Modal }),
],
});

Expand Down
5 changes: 5 additions & 0 deletions examples/angular/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@
"glob": "**/*",
"input": "packages/near-mobile-wallet/assets/",
"output": "assets/"
},
{
"glob": "**/*",
"input": "packages/ethereum-wallets/assets/",
"output": "assets/"
}
],
"styles": ["examples/angular/src/styles.scss"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ import { setupRamperWallet } from "@near-wallet-selector/ramper-wallet";
import { setupLedger } from "@near-wallet-selector/ledger";
import { setupNearMobileWallet } from "@near-wallet-selector/near-mobile-wallet";
import { setupMintbaseWallet } from "@near-wallet-selector/mintbase-wallet";
import { setupEthereumWallets } from "@near-wallet-selector/ethereum-wallets";
import { createWeb3Modal } from "@web3modal/wagmi";
import { reconnect, http, createConfig, type Config } from "@wagmi/core";
import { type Chain } from "@wagmi/core/chains";
import { injected, walletConnect } from "@wagmi/connectors";
import { CONTRACT_ID } from "../../../constants";

declare global {
Expand All @@ -32,6 +37,61 @@ declare global {
}
}

// Get a project ID at https://cloud.walletconnect.com
const projectId = "30147604c5f01d0bc4482ab0665b5697";

// NOTE: This is the NEAR wallet playground used in dev mode.
// TODO: Replace with the NEAR chain after the protocol upgrade.
const near: Chain = {
id: 398,
name: "NEAR wallet playground",
nativeCurrency: {
decimals: 18,
name: "NEAR",
symbol: "NEAR",
},
rpcUrls: {
default: { http: ["https://near-wallet-relayer.testnet.aurora.dev"] },
public: { http: ["https://near-wallet-relayer.testnet.aurora.dev"] },
},
blockExplorers: {
default: {
name: "NEAR Explorer",
url: "https://testnet.nearblocks.io",
},
},
testnet: true,
};

const wagmiConfig: Config = createConfig({
chains: [near],
transports: {
[near.id]: http(),
},
connectors: [
walletConnect({
projectId,
metadata: {
name: "NEAR Guest Book",
description: "A guest book with comments stored on the NEAR blockchain",
url: "https://near.github.io/wallet-selector",
icons: ["https://near.github.io/wallet-selector/favicon.ico"],
},
showQrModal: false,
}),
injected({ shimDisconnect: true }),
],
});
reconnect(wagmiConfig);

const web3Modal = createWeb3Modal({
wagmiConfig: wagmiConfig,
projectId,
featuredWalletIds: [
"ecc4036f814562b41a5268adc86270fba1365471402006302e70169465b7ac18", // Zerion
],
});
Patrick1904 marked this conversation as resolved.
Show resolved Hide resolved

@Component({
selector: "near-wallet-selector-wallet-selector",
templateUrl: "./wallet-selector.component.html",
Expand Down Expand Up @@ -93,6 +153,7 @@ export class WalletSelectorComponent implements OnInit {
setupRamperWallet(),
setupNearMobileWallet(),
setupMintbaseWallet({ contractId: "guest-book.testnet" }),
setupEthereumWallets({ wagmiConfig, web3Modal, devMode: true }),
],
});

Expand Down
61 changes: 61 additions & 0 deletions examples/react/contexts/WalletSelectorContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { setupXDEFI } from "@near-wallet-selector/xdefi";
import { setupRamperWallet } from "@near-wallet-selector/ramper-wallet";
import { setupNearMobileWallet } from "@near-wallet-selector/near-mobile-wallet";
import { setupMintbaseWallet } from "@near-wallet-selector/mintbase-wallet";
import { setupEthereumWallets } from "@near-wallet-selector/ethereum-wallets";

import type { ReactNode } from "react";
import React, {
Expand All @@ -31,6 +32,10 @@ import React, {
useMemo,
} from "react";
import { distinctUntilChanged, map } from "rxjs";
import { createWeb3Modal } from "@web3modal/wagmi";
import { reconnect, http, createConfig, type Config } from "@wagmi/core";
import { type Chain } from "@wagmi/core/chains";
import { injected, walletConnect } from "@wagmi/connectors";

import { Loading } from "../components/Loading";
import { CONTRACT_ID } from "../constants";
Expand All @@ -52,6 +57,61 @@ interface WalletSelectorContextValue {
const WalletSelectorContext =
React.createContext<WalletSelectorContextValue | null>(null);

// Get a project ID at https://cloud.walletconnect.com
const projectId = "30147604c5f01d0bc4482ab0665b5697";

// NOTE: This is the NEAR wallet playground used in dev mode.
// TODO: Replace with the NEAR chain after the protocol upgrade.
const near: Chain = {
id: 398,
name: "NEAR wallet playground",
nativeCurrency: {
decimals: 18,
name: "NEAR",
symbol: "NEAR",
},
rpcUrls: {
default: { http: ["https://near-wallet-relayer.testnet.aurora.dev"] },
public: { http: ["https://near-wallet-relayer.testnet.aurora.dev"] },
},
blockExplorers: {
default: {
name: "NEAR Explorer",
url: "https://testnet.nearblocks.io",
},
},
testnet: true,
};

const wagmiConfig: Config = createConfig({
chains: [near],
transports: {
[near.id]: http(),
},
connectors: [
walletConnect({
projectId,
metadata: {
name: "NEAR Guest Book",
description: "A guest book with comments stored on the NEAR blockchain",
url: "https://near.github.io/wallet-selector",
icons: ["https://near.github.io/wallet-selector/favicon.ico"],
},
showQrModal: false,
}),
injected({ shimDisconnect: true }),
],
});
reconnect(wagmiConfig);

const web3Modal = createWeb3Modal({
wagmiConfig: wagmiConfig,
projectId,
featuredWalletIds: [
"ecc4036f814562b41a5268adc86270fba1365471402006302e70169465b7ac18", // Zerion
],
});

export const WalletSelectorContextProvider: React.FC<{
children: ReactNode;
}> = ({ children }) => {
Expand Down Expand Up @@ -95,6 +155,7 @@ export const WalletSelectorContextProvider: React.FC<{
}),
setupNearMobileWallet(),
setupMintbaseWallet({ contractId: "guest-book.testnet" }),
setupEthereumWallets({ wagmiConfig, web3Modal, devMode: true }),
],
});
const _modal = setupModal(_selector, {
Expand Down
5 changes: 5 additions & 0 deletions examples/react/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
"glob": "**/*",
"input": "packages/near-mobile-wallet/assets/",
"output": "assets/"
},
{
"glob": "**/*",
"input": "packages/ethereum-wallets/assets/",
"output": "assets/"
}
]
},
Expand Down
45 changes: 25 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"nightly",
"ledger",
"wallet-connect",
"ethereum-wallets",
"nearfi",
"meteor-wallet",
"welldone-wallet",
Expand Down Expand Up @@ -64,6 +65,7 @@
"build:ramper-wallet": "nx run-many --target=build --projects=ramper-wallet --configuration=production",
"build:near-mobile-wallet": "nx run-many --target=build --projects=near-mobile-wallet --configuration=production",
"build:mintbase-wallet": "nx run-many --target=build --projects=mintbase-wallet --configuration=production",
"build:ethereum-wallets": "nx run-many --target=build --projects=ethereum-wallets --configuration=production",
"examples:vanillajs:generateimportmap": "(cd examples/vanillajs && jspm link index.html -o index.html)",
"serve:vanillajs": "yarn examples:vanillajs:generateimportmap && http-server -c-1 examples/vanillajs",
"lint": "nx workspace-lint && nx run-many --target=lint --all --parallel",
Expand All @@ -72,19 +74,18 @@
"serve:angular": "nx serve angular",
"prepack": "yarn build:core && yarn build:all",
"test": "nx run-many --target=test --all",
"postinstall": "ngcc --properties es2020 browser module main",
"find:unused": "ts-prune -p tsprune.json"
},
"dependencies": {
"@angular/animations": "15.2.9",
"@angular/common": "15.2.9",
"@angular/compiler": "15.2.9",
"@angular/core": "15.2.9",
"@angular/forms": "15.2.9",
"@angular/platform-browser": "15.2.9",
"@angular/platform-browser-dynamic": "15.2.9",
"@angular/router": "15.2.9",
"@here-wallet/core": "^1.6.6",
"@angular/animations": "16.1.9",
"@angular/common": "16.1.9",
"@angular/compiler": "16.1.9",
"@angular/core": "16.1.9",
"@angular/forms": "16.1.9",
"@angular/platform-browser": "16.1.9",
"@angular/platform-browser-dynamic": "16.1.9",
"@angular/router": "16.1.9",
"@here-wallet/core": "^1.5.1",
"@jscutlery/semver": "3.1.0",
"@ledgerhq/hw-transport": "6.30.3",
"@ledgerhq/hw-transport-webhid": "6.28.3",
Expand All @@ -94,8 +95,10 @@
"@near-snap/sdk": "^0.6.0",
"@peersyst/near-mobile-signer": "^1.0.10",
"@ramper/near": "^0.0.30",
"@tanstack/react-query": "5.36.2",
"@walletconnect/modal": "^2.6.2",
"@walletconnect/sign-client": "2.11.0",
"@walletconnect/sign-client": "2.13.0",
"@web3modal/wagmi": "4.2.0",
"better-sqlite3": "^9.3.0",
"big.js": "^6.1.1",
"bn.js": "^5.2.0",
Expand Down Expand Up @@ -125,29 +128,31 @@
"tweetnacl": "^1.0.3",
"tweetnacl-util": "^0.15.1",
"url": "^0.11.0",
"viem": "2.10.5",
"wagmi": "2.8.8",
"zone.js": "0.12.0"
},
"devDependencies": {
"@angular-devkit/build-angular": "15.2.8",
"@angular-devkit/core": "15.2.8",
"@angular-devkit/schematics": "15.2.8",
"@angular-devkit/build-angular": "16.1.8",
"@angular-devkit/core": "16.1.8",
"@angular-devkit/schematics": "16.1.8",
"@angular-eslint/eslint-plugin": "15.0.0",
"@angular-eslint/eslint-plugin-template": "15.0.0",
"@angular-eslint/template-parser": "15.0.0",
"@angular/cli": "~15.2.0",
"@angular/compiler-cli": "15.2.9",
"@angular/cli": "16.1.8",
"@angular/compiler-cli": "16.1.8",
"@angular/language-service": "15.2.9",
"@babel/preset-react": "^7.16.7",
"@nrwl/js": "16.0.0",
"@nrwl/rollup": "16.0.0",
"@nrwl/tao": "16.0.0",
"@nrwl/webpack": "16.0.0",
"@nx/angular": "16.0.0",
"@nx/angular": "16.4.0",
"@nx/cypress": "16.0.0",
"@nx/eslint-plugin": "16.0.0",
"@nx/jest": "16.0.0",
"@nx/js": "16.0.0",
"@nx/linter": "16.0.0",
"@nx/linter": "16.4.0",
"@nx/next": "16.0.0",
"@nx/react": "16.0.0",
"@nx/web": "16.0.0",
Expand Down Expand Up @@ -193,7 +198,7 @@
"jest-preset-angular": "13.0.0",
"jsdoc": "^4.0.2",
"jspm": "^3.1.0",
"nx": "16.0.0",
"nx": "16.4.0",
"nx-cloud": "16.0.5",
"path-browserify": "^1.0.1",
"prettier": "^2.7.1",
Expand All @@ -207,7 +212,7 @@
"ts-jest": "29.1.0",
"ts-node": "10.9.1",
"ts-prune": "^0.10.3",
"typescript": "4.9.5",
"typescript": "5.0.4",
"url-loader": "^4.1.1",
"util": "^0.12.5",
"webpack": "^5.75.0",
Expand Down
11 changes: 11 additions & 0 deletions packages/ethereum-wallets/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"presets": [
[
"@nrwl/js/babel",
{
"useBuiltIns": "usage"
}
]
],
"plugins": []
}
18 changes: 18 additions & 0 deletions packages/ethereum-wallets/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
Loading
Loading