Skip to content

Support EIP-6963: Multi Injected Provider Discovery #312

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

Merged
merged 51 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 36 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
74f0e55
connectorlist
lochie Oct 18, 2023
99351cd
remove: transparent family logo
lochie Oct 25, 2023
9978f03
install mipd
lochie Oct 25, 2023
0e3baef
squircle spinner
lochie Oct 25, 2023
fa31bd3
scroll component
lochie Oct 25, 2023
9e16c4e
include midp wallets in default config
lochie Oct 25, 2023
5992688
useWallets hook + configs
lochie Oct 25, 2023
eb3f557
update connector list
lochie Oct 25, 2023
2c40a7a
use wallet hook, new connector routes, replacing config logic
lochie Oct 25, 2023
3c68a86
icon cleanup + connect fixes
lochie Oct 26, 2023
cf1398c
fix: deeplinks
lochie Oct 26, 2023
cd9ff78
edge cases, fix mobile routes and missing elements
lochie Oct 26, 2023
a4762cc
override cleanup
lochie Oct 26, 2023
65edcf4
spinner configs
lochie Oct 27, 2023
480f904
more configs
lochie Oct 27, 2023
40e1d59
config updates
lochie Nov 17, 2023
b9f02b2
avoid duplicate wallets
lochie Nov 17, 2023
8ac6030
types
lochie Nov 29, 2023
32db257
allow scanning if connector not ready
lochie Nov 29, 2023
b8a8e4e
consolidate wallet checks
lochie Nov 29, 2023
74ea9ba
fix: mobile scroll + walletconnect border radius
lochie Nov 29, 2023
d28fe95
align configs, flags for smaller icons, misc. updates
lochie Nov 30, 2023
c900f82
fix: missing download url change
lochie Nov 30, 2023
eaea3b6
bring recent to top
lochie Nov 30, 2023
44f6226
safe app update
lochie Nov 30, 2023
2803cb7
fix: injected mismatches
lochie Nov 30, 2023
c89055b
fix: mm icon size
lochie Dec 5, 2023
2fb8799
fix: remove doubled up wallets
lochie Dec 5, 2023
1b87873
add: more scroll available tooltip
lochie Dec 6, 2023
04ee57c
update: click to scroll tooltip
lochie Dec 6, 2023
0c218a4
update: hide legacy connectors without a name
lochie Dec 6, 2023
5e953a2
cleanup
lochie Dec 6, 2023
78e6e53
fix: duplicate wallet detection
lochie Dec 7, 2023
cd46469
remove: unnecessary iconBackground prop
lochie Dec 8, 2023
1573a78
add: family logo to other wallets icon
lochie Dec 8, 2023
95646da
fix: missed file
lochie Dec 8, 2023
9e00f0d
Fix typo: MIDP > MIPD
lochie Dec 8, 2023
f7dcc88
mobile other wallets cleanup
lochie Dec 8, 2023
dc6622c
fix: do not hoist walletconnect to top of list
lochie Jan 9, 2024
923900f
cleanup logos
lochie Jan 9, 2024
9f0ab20
rename old EIP-1193 to legacy
lochie Jan 9, 2024
215a0c2
Merge branch 'main' into eip-6963
lochie Jan 9, 2024
eba461d
avoid doubling up on logos
lochie Jan 9, 2024
a299543
mobile border radius
lochie Jan 9, 2024
6df567b
eip6963 config for Family wallet
lochie Jan 9, 2024
aa2ae40
fix: types
lochie Jan 10, 2024
fbf9735
fix: legacy injected wallets
lochie Jan 10, 2024
f43a2cd
dev log
lochie Jan 10, 2024
7585d5e
temp dev log
lochie Jan 10, 2024
ce3916a
dev
lochie Jan 10, 2024
4585985
remove dev
lochie Jan 10, 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
11 changes: 11 additions & 0 deletions examples/testbench/src/pages/iframe.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { NextPage } from 'next';

const Ledger: NextPage = () => {
return (
<>
<iframe src="/" style={{ width: '100%', height: '100vh' }} />
</>
);
};

export default Ledger;
1 change: 1 addition & 0 deletions packages/connectkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"buffer": "^6.0.3",
"detect-browser": "^5.3.0",
"framer-motion": "^6.3.11",
"mipd": "^0.0.5",
"qrcode": "^1.5.0",
"react-transition-state": "^1.1.4",
"react-use-measure": "^2.1.1",
Expand Down
30 changes: 6 additions & 24 deletions packages/connectkit/src/assets/logos.tsx

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions packages/connectkit/src/components/Common/Alert/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React from 'react';
import { AlertProps } from './types';
import { AlertContainer, IconContainer } from './styles';

const Alert = ({ children, icon }: AlertProps) => {
const Alert = ({ children, error, icon }: AlertProps) => {
return (
<AlertContainer>
<AlertContainer $error={error}>
{icon && <IconContainer>{icon}</IconContainer>}
<div>{children}</div>
</AlertContainer>
Expand Down
11 changes: 10 additions & 1 deletion packages/connectkit/src/components/Common/Alert/styles.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import styled from './../../../styles/styled';
import { motion } from 'framer-motion';
import defaultTheme from '../../../constants/defaultTheme';
import { css } from 'styled-components';

export const AlertContainer = styled(motion.div)`
export const AlertContainer = styled(motion.div)<{ $error?: boolean }>`
display: flex;
gap: 8px;
position: relative;
Expand All @@ -28,6 +29,14 @@ export const AlertContainer = styled(motion.div)`
border-radius: 24px;
text-align: center;
}

${($error) => {
if ($error)
return css`
color: #fff;
background: var(--ck-body-color-danger, red);
`;
}}
`;

export const IconContainer = styled(motion.div)`
Expand Down
1 change: 1 addition & 0 deletions packages/connectkit/src/components/Common/Alert/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type AlertProps = {
children?: React.ReactNode;
icon?: React.ReactNode;
error?: boolean;
};
165 changes: 165 additions & 0 deletions packages/connectkit/src/components/Common/ConnectorList/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
import { useContext, routes } from '../../ConnectKit';

import {
ConnectorsContainer,
ConnectorButton,
ConnectorLabel,
ConnectorIcon,
RecentlyUsedTag,
} from './styles';

import { useWallets } from '../../../hooks/useWallets';
import { useInjectedWallet } from '../../../hooks/connectors/useInjectedWallet';
import { isInjectedConnector, isWalletConnectConnector } from '../../../utils';

import { useWalletConnectUri } from '../../../hooks/connectors/useWalletConnectUri';
import { useLastConnector } from '../../../hooks/useLastConnector';
import useIsMobile from '../../../hooks/useIsMobile';

import { ScrollArea } from '../../Common/ScrollArea';
import Alert from '../Alert';

const ConnectorList = () => {
const context = useContext();
const isMobile = useIsMobile();

const { uri } = useWalletConnectUri();
const { lastConnectorId } = useLastConnector();
const injectedWallet = useInjectedWallet();

const wallets = useWallets();

const walletsToDisplay = context.options?.hideRecentBadge
? wallets
: [
// move last used wallet to top of list
// using .filter and spread to avoid mutating original array order with .sort
...wallets.filter(
(wallet) =>
lastConnectorId ===
`${wallet.connector.id}-${wallet.connector.name}`
),
...wallets.filter(
(wallet) =>
lastConnectorId !==
`${wallet.connector.id}-${wallet.connector.name}`
),
];

return (
<ScrollArea>
{walletsToDisplay.length === 0 && (
<Alert error>No connectors found in ConnectKit config.</Alert>
)}
{walletsToDisplay.length > 0 && (
<ConnectorsContainer
$mobile={isMobile}
$totalResults={walletsToDisplay.length}
>
{walletsToDisplay.map((wallet) => {
const {
id,
name,
shortName,
icon,
iconConnector,
connector,
createUri,
} = wallet;

let deeplink = isMobile ? createUri?.(uri ?? '') : undefined;

const redirectToMoreWallets =
isMobile && isWalletConnectConnector(id);

if (isInjectedConnector(id) && !injectedWallet.enabled) return null;
if (redirectToMoreWallets) deeplink = undefined; // mobile redirects to more wallets page

const walletInfo =
isInjectedConnector(wallet.id) && injectedWallet.enabled
? // && injectedWallet.wallet.name === wallet.name
{
name: injectedWallet.wallet.name,
shortName:
injectedWallet.wallet.shortName ??
injectedWallet.wallet.name,
icon: injectedWallet.wallet.icon,
//iconRadius: 0,
}
: {
name: name,
shortName: shortName ?? name,
icon: iconConnector ?? icon,
iconRadius: wallet.id === 'walletConnect' ? 0 : undefined,
};

const ButtonInner = ({
disabled = false,
}: {
disabled?: boolean;
}) => (
<ConnectorButton
as={deeplink ? 'a' : undefined}
href={deeplink ? deeplink : undefined}
disabled={disabled || context.route !== routes.CONNECTORS}
onClick={
deeplink
? undefined
: () => {
if (redirectToMoreWallets) {
context.setRoute(routes.MOBILECONNECTORS);
} else {
context.setRoute(routes.CONNECT);
context.setConnector({ id: id, name: name });
}
}
}
>
<ConnectorIcon
data-small={wallet.iconShouldShrink}
style={{
borderRadius: walletInfo.iconRadius,
}}
>
{walletInfo.icon}
</ConnectorIcon>
<ConnectorLabel>
{isMobile ? walletInfo.shortName : walletInfo.name}
{!context.options?.hideRecentBadge &&
lastConnectorId === `${connector.id}-${connector.name}` && (
<RecentlyUsedTag>
<span>Recent</span>
</RecentlyUsedTag>
)}
</ConnectorLabel>
</ConnectorButton>
);
/*
if (!connector.ready && injectedWallet.enabled) {
return (
<Tooltip
key={id}
xOffset={18}
message={
<div style={{ width: 230, padding: '6px 4px' }}>
{name} Unavailable as {injectedWallet?.wallet?.name} is
installed. Disable {injectedWallet?.wallet?.name} to
connect with {name}.
</div>
}
delay={0}
>
<ButtonInner disabled />
</Tooltip>
);
}
*/
return <ButtonInner key={id} />;
})}
</ConnectorsContainer>
)}
</ScrollArea>
);
};

export default ConnectorList;
Loading