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

Use MetaMask SDK connector #178

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions .changeset/modern-tomatoes-remain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@reef-knot/connect-wallet-modal": minor
"@reef-knot/wallet-adapter-metamask": minor
"reef-knot": minor
---

MetaMask connection: switch to MetaMask SDK connector from regular injected connector
2 changes: 1 addition & 1 deletion apps/demo-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"tiny-invariant": "^1.3.1",
"url-loader": "^4.1.1",
"viem": "2.13.3",
"wagmi": "2.11.2"
"wagmi": "2.12.25"
},
"devDependencies": {
"@babel/core": "^7.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/connect-wallet-modal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"react": "18.2.0",
"react-dom": "^18.2.0",
"viem": "2.13.3",
"wagmi": "2.11.2"
"wagmi": "2.12.25"
},
"peerDependencies": {
"@reef-knot/core-react": "^4.0.0",
Expand All @@ -68,7 +68,7 @@
"react": ">=18",
"@lidofinance/lido-ui": "^3.18.0",
"viem": "2.13.3",
"wagmi": "2.11.2",
"wagmi": "2.12.25",
"@tanstack/react-query": "^5.29.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ConnectCoinbase,
ConnectBrowser,
ConnectBinance,
ConnectMetaMask,
} from '../../connectButtons';
import { WalletsModal } from './WalletsModal';
import type { WalletIdsEthereum } from '@reef-knot/wallets-list';
Expand All @@ -21,6 +22,7 @@ const buttonComponentsByConnectorId: WalletsModalEthProps['buttonComponentsByCon
coinbaseWallet: ConnectCoinbase,
ledgerHID: ConnectLedger,
binanceWallet: ConnectBinance,
metaMask: ConnectMetaMask,
};

const WALLETS_DISPLAY_CONFIG_DEFAULT: WalletsModalEthProps['walletsShown'] = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React, { FC, useCallback } from 'react';
import { useConnect } from 'wagmi';
import { useDisconnect } from '@reef-knot/core-react';
import { ConnectButton } from '../components/ConnectButton';
import { ConnectInjectedProps } from './types';

export const ConnectMetaMask: FC<ConnectInjectedProps> = (
props: ConnectInjectedProps,
) => {
const {
onConnect,
onBeforeConnect,
shouldInvertWalletIcon,
metrics,
walletId,
walletName,
icon: WalletIcon,
downloadURLs,
detector,
connector,
...rest
} = props;

const metricsOnConnect = metrics?.events?.connect?.handlers[walletId];
const metricsOnClick = metrics?.events?.click?.handlers[walletId];

const { connect } = useConnect();
const { disconnect } = useDisconnect();

const handleConnect = useCallback(() => {
onBeforeConnect?.();
metricsOnClick?.();
disconnect?.();
connect(
{ connector },
{
onSuccess: () => {
onConnect?.();
metricsOnConnect?.();
},
},
);
}, [
connect,
connector,
disconnect,
metricsOnClick,
onBeforeConnect,
onConnect,
metricsOnConnect,
]);

return (
<ConnectButton
{...rest}
icon={WalletIcon}
shouldInvertWalletIcon={shouldInvertWalletIcon}
onClick={handleConnect}
>
{walletName}
</ConnectButton>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './ConnectWC';
export * from './ConnectCoinbase';
export * from './ConnectBrowser';
export * from './ConnectBinance';
export * from './ConnectMetaMask';
4 changes: 2 additions & 2 deletions packages/connectors/ledger-connector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"devDependencies": {
"@types/w3c-web-hid": "^1.0.2",
"viem": "2.13.3",
"wagmi": "2.11.2",
"wagmi": "2.12.25",
"eslint-config-custom": "*"
},
"dependencies": {
Expand All @@ -57,7 +57,7 @@
},
"peerDependencies": {
"viem": "2.13.3",
"wagmi": "2.11.2",
"wagmi": "2.12.25",
"@tanstack/react-query": "^5.29.0"
}
}
4 changes: 2 additions & 2 deletions packages/core-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"eslint-config-custom": "*",
"react": "18.2.0",
"viem": "2.13.3",
"wagmi": "2.11.2",
"wagmi": "2.12.25",
"mipd": "0.0.7"
},
"peerDependencies": {
Expand All @@ -56,7 +56,7 @@
"@reef-knot/wallets-helpers": "^2.0.2",
"react": ">=18",
"viem": "2.13.3",
"wagmi": "2.11.2",
"wagmi": "2.12.25",
"@tanstack/react-query": "^5.29.0"
}
}
2 changes: 1 addition & 1 deletion packages/reef-knot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"react-dom": ">=18",
"styled-components": "^5.3.5",
"viem": "2.13.3",
"wagmi": "2.11.2"
"wagmi": "2.12.25"
},
"devDependencies": {
"eslint-config-custom": "*"
Expand Down
4 changes: 2 additions & 2 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
},
"devDependencies": {
"react": "18.2.0",
"wagmi": "2.11.2"
"wagmi": "2.12.25"
},
"peerDependencies": {
"react": ">=18",
"wagmi": "2.11.2",
"wagmi": "2.12.25",
"@tanstack/react-query": "^5.29.0"
}
}
4 changes: 2 additions & 2 deletions packages/ui-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@
"react": ">=18",
"react-dom": ">=18",
"styled-components": "5",
"wagmi": "2.11.2"
"wagmi": "2.12.25"
},
"devDependencies": {
"@types/react-transition-group": "4.4.2",
"eslint-config-custom": "*",
"react": "18.2.0",
"react-dom": "18.2.0",
"styled-components": "^5.3.6",
"wagmi": "2.11.2",
"wagmi": "2.12.25",
"@tanstack/react-query": "^5.29.0"
}
}
4 changes: 2 additions & 2 deletions packages/wallets-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
},
"devDependencies": {
"eslint-config-custom": "*",
"wagmi": "2.11.2"
"wagmi": "2.12.25"
},
"peerDependencies": {
"react": ">=18",
"wagmi": "2.11.2",
"wagmi": "2.12.25",
"@tanstack/react-query": "^5.29.0"
}
}
2 changes: 1 addition & 1 deletion packages/wallets/ambire/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"eslint-config-custom": "*"
},
"peerDependencies": {
"wagmi": "2.11.2",
"wagmi": "2.12.25",
"@reef-knot/wallets-helpers": "^2.0.0",
"@reef-knot/types": "^2.0.0",
"@tanstack/react-query": "^5.29.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/bitkeep/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"eslint-config-custom": "*"
},
"peerDependencies": {
"wagmi": "2.11.2",
"wagmi": "2.12.25",
"@reef-knot/types": "^2.0.1",
"@reef-knot/wallets-helpers": "^2.0.2",
"@tanstack/react-query": "^5.29.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/brave/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"eslint-config-custom": "*"
},
"peerDependencies": {
"wagmi": "2.11.2",
"wagmi": "2.12.25",
"@reef-knot/types": "^2.0.1",
"@reef-knot/wallets-helpers": "^2.0.2",
"@tanstack/react-query": "^5.29.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/browserExtension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"eslint-config-custom": "*"
},
"peerDependencies": {
"wagmi": "2.11.2",
"wagmi": "2.12.25",
"@reef-knot/types": "^2.0.0",
"@tanstack/react-query": "^5.29.0"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/coin98/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@svgr/rollup": "^6.5.1"
},
"peerDependencies": {
"wagmi": "2.11.2",
"wagmi": "2.12.25",
"@reef-knot/types": "^2.0.1",
"@reef-knot/wallets-helpers": "^2.0.2",
"@tanstack/react-query": "^5.29.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/coinbase-smart-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"eslint-config-custom": "*"
},
"peerDependencies": {
"wagmi": "2.10.4",
"wagmi": "2.12.25",
"@reef-knot/types": "^2.0.0",
"@tanstack/react-query": "^5.29.0"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/coinbase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"eslint-config-custom": "*"
},
"peerDependencies": {
"wagmi": "2.11.2",
"wagmi": "2.12.25",
"@reef-knot/types": "^2.0.1",
"@reef-knot/wallets-helpers": "^2.0.2",
"@tanstack/react-query": "^5.29.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/dappBrowserInjected/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"eslint-config-custom": "*"
},
"peerDependencies": {
"wagmi": "2.11.2",
"wagmi": "2.12.25",
"@reef-knot/types": "^2.0.0",
"@reef-knot/wallets-helpers": "^2.0.0",
"@tanstack/react-query": "^5.29.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/exodus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"eslint-config-custom": "*"
},
"peerDependencies": {
"wagmi": "2.11.2",
"wagmi": "2.12.25",
"@reef-knot/types": "^2.0.1",
"@reef-knot/wallets-helpers": "^2.0.2",
"@tanstack/react-query": "^5.29.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/imtoken/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"eslint-config-custom": "*"
},
"peerDependencies": {
"wagmi": "2.11.2",
"wagmi": "2.12.25",
"@reef-knot/types": "^2.0.0",
"@tanstack/react-query": "^5.29.0"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/ledger-hid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"eslint-config-custom": "*"
},
"peerDependencies": {
"wagmi": "2.11.2",
"wagmi": "2.12.25",
"@reef-knot/types": "^2.0.0",
"@reef-knot/ledger-connector": "^4.0.0",
"@tanstack/react-query": "^5.29.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/ledger-live/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"eslint-config-custom": "*"
},
"peerDependencies": {
"wagmi": "2.11.2",
"wagmi": "2.12.25",
"@reef-knot/types": "^2.0.0",
"@reef-knot/ledger-connector": "^4.0.0",
"@tanstack/react-query": "^5.29.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/metamask/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"eslint-config-custom": "*"
},
"peerDependencies": {
"wagmi": "2.11.2",
"wagmi": "2.12.25",
"@reef-knot/types": "^2.0.1",
"@reef-knot/wallets-helpers": "^2.0.2",
"@tanstack/react-query": "^5.29.0"
Expand Down
19 changes: 3 additions & 16 deletions packages/wallets/metamask/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import { injected } from 'wagmi/connectors';
import { injected, metaMask } from 'wagmi/connectors';
import type { WalletAdapterType } from '@reef-knot/types';
import {
getTargetEIP6963,
isProviderExistsEIP6963,
} from '@reef-knot/wallets-helpers';
import { isProviderExistsEIP6963 } from '@reef-knot/wallets-helpers';
import { WalletIcon, WalletIconInverted } from './icons/index.js';

export const id = 'metaMask';
export const name = 'MetaMask';
export const rdns = 'io.metamask';
const currentHref = globalThis.window
? globalThis.window.location.hostname + globalThis.window.location.pathname // encoding not supported
: '';

export const MetaMask: WalletAdapterType = ({ providersStore }) => ({
walletName: name,
Expand All @@ -22,12 +16,5 @@ export const MetaMask: WalletAdapterType = ({ providersStore }) => ({
dark: WalletIconInverted,
},
detector: () => isProviderExistsEIP6963(providersStore, rdns),
downloadURLs: {
default: 'https://metamask.io/download/',
},
deeplink: `https://metamask.app.link/dapp/${currentHref}`,
createConnectorFn: injected({
target: () => getTargetEIP6963(providersStore, rdns),
shimDisconnect: true,
}),
createConnectorFn: metaMask(),
});
2 changes: 1 addition & 1 deletion packages/wallets/okx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"eslint-config-custom": "*"
},
"peerDependencies": {
"wagmi": "2.11.2",
"wagmi": "2.12.25",
"@reef-knot/types": "^2.0.1",
"@reef-knot/wallets-helpers": "^2.0.2",
"@tanstack/react-query": "^5.29.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/phantom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"eslint-config-custom": "*"
},
"peerDependencies": {
"wagmi": "2.11.2",
"wagmi": "2.12.25",
"@reef-knot/types": "^2.0.1",
"@reef-knot/wallets-helpers": "^2.0.2",
"@tanstack/react-query": "^5.29.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/safe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"peerDependencies": {
"viem": "2.13.3",
"wagmi": "2.11.2",
"wagmi": "2.12.25",
"@reef-knot/types": "^2.0.0",
"@tanstack/react-query": "^5.29.0"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/trust/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"eslint-config-custom": "*"
},
"peerDependencies": {
"wagmi": "2.11.2",
"wagmi": "2.12.25",
"@reef-knot/types": "^2.0.1",
"@reef-knot/wallets-helpers": "^2.0.2",
"@tanstack/react-query": "^5.29.0"
Expand Down
Loading
Loading