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

Connectkit support telegram web apps #415

Open
wants to merge 5 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
2 changes: 2 additions & 0 deletions examples/nextjs-app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

certificates
45 changes: 45 additions & 0 deletions examples/nextjs-app/app/LogDisplay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// @ts-nocheck
'use client';


import { useEffect, useState } from 'react';

function LogDisplay() {
const [logs, setLogs] = useState<string[]>([]);

useEffect(() => {
// Override console.log to capture logs
const originalConsoleLog = console.log;
console.log = function(...args) {
const logMessage = args.join(' ');
const event = new CustomEvent('log', { detail: logMessage });
window.dispatchEvent(event);
originalConsoleLog.apply(console, args);
};

// Listen for log events
const handleLogEvent = (event: CustomEvent) => {
setLogs((prevLogs) => [...prevLogs, event.detail]);
};

window.addEventListener('log', handleLogEvent);

return () => {
window.removeEventListener('log', handleLogEvent);
console.log = originalConsoleLog; // Restore original console.log
};
}, []);

return (
<div style={{ padding: '10px', backgroundColor: '#333', color: '#fff', fontFamily: 'monospace' }}>
<h2>Logs</h2>
<div style={{ maxHeight: '300px', overflowY: 'auto' }}>
{logs.map((log, index) => (
<div key={index}>{log}</div>
))}
</div>
</div>
);
}

export default LogDisplay;
2 changes: 2 additions & 0 deletions examples/nextjs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

certificates
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"dev:connectkit-next-siwe": "yarn workspace connectkit-next-siwe run dev",
"dev:cra": "yarn workspace cra run dev",
"dev:nextjs": "yarn workspace nextjs run dev",
"dev:nextjs:https": "yarn workspace nextjs run dev --experimental-https",
"dev:nextjs-app": "yarn workspace nextjs-app run dev",
"dev:nextjs-app:https": "yarn workspace nextjs-app run dev --experimental-https",
"dev:nextjs-siwe": "yarn workspace nextjs-siwe run dev",
"dev:vite": "yarn workspace vite run dev",
"dev:testbench": "yarn workspace testbench run dev",
Expand Down
2 changes: 1 addition & 1 deletion packages/connectkit/rollup.config.prod.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import typescript from 'rollup-plugin-typescript2';

import packageJson from './package.json';
import packageJson from './package.json' assert { type: 'json' };

export default [
{
Expand Down
38 changes: 20 additions & 18 deletions packages/connectkit/src/components/Common/ConnectorList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Alert from '../Alert';
import { WalletProps, useWallets } from '../../../wallets/useWallets';
import {
detectBrowser,
isAndroid,
isCoinbaseWalletConnector,
isWalletConnectConnector,
} from '../../../utils';
Expand All @@ -34,15 +35,15 @@ const ConnectorList = () => {
context.options?.hideRecentBadge || lastConnectorId === 'walletConnect' // do not hoist walletconnect to top of list
? 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
),
...wallets.filter(
(wallet) => lastConnectorId !== wallet.connector.id
),
];
// 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
),
...wallets.filter(
(wallet) => lastConnectorId !== wallet.connector.id
),
];

return (
<ScrollArea mobileDirection={'horizontal'}>
Expand Down Expand Up @@ -97,7 +98,7 @@ const ConnectorItem = ({

let deeplink =
(!wallet.isInstalled && isMobile) ||
(wallet.shouldDeeplinkDesktop && !isMobile)
(wallet.shouldDeeplinkDesktop && !isMobile)
? wallet.getWalletConnectDeeplink?.(uri ?? '')
: undefined;

Expand All @@ -114,21 +115,22 @@ const ConnectorItem = ({
type="button"
as={deeplink ? 'a' : undefined}
href={deeplink ? deeplink : undefined}
target={deeplink && isAndroid() ? '_blank' : undefined}
disabled={context.route !== routes.CONNECTORS}
onClick={
deeplink
? undefined
: () => {
if (redirectToMoreWallets) {
context.setRoute(routes.MOBILECONNECTORS);
} else {
if (shouldConnectImmediately) {
connect({ connector: wallet?.connector });
}
context.setRoute(routes.CONNECT);
context.setConnector({ id: wallet.id });
if (redirectToMoreWallets) {
context.setRoute(routes.MOBILECONNECTORS);
} else {
if (shouldConnectImmediately) {
connect({ connector: wallet?.connector });
}
context.setRoute(routes.CONNECT);
context.setConnector({ id: wallet.id });
}
}
}
>
<ConnectorIcon
Expand Down