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

Fixed telegram login issue #5142

Merged
merged 2 commits into from
Dec 19, 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
38 changes: 18 additions & 20 deletions components/_app/components/ConnectedAccounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,27 +137,25 @@ function TelegramAccountConnect({
const { connectTelegram, isConnectingToTelegram } = useTelegramConnect();

return (
<>
<ConnectedAccount
label='Telegram'
icon={<IdentityIcon type='Telegram' size='small' />}
required={isTelegramRequired}
disabled={!!connectedTelegramAccount || isConnectingToTelegram}
onClick={() => {
setIsOnboardingModalOpen(true);
connectTelegram();
}}
>
{!connectedTelegramAccount ? (
<Typography variant='subtitle1'>Connect with Telegram</Typography>
) : (
<Typography variant='subtitle1'>
Connected as {(connectedTelegramAccount.account as unknown as Partial<TelegramAccount>)?.username}
</Typography>
)}
</ConnectedAccount>
<ConnectedAccount
label='Telegram'
icon={<IdentityIcon type='Telegram' size='small' />}
required={isTelegramRequired}
disabled={!!connectedTelegramAccount || isConnectingToTelegram}
onClick={() => {
setIsOnboardingModalOpen(true);
connectTelegram();
}}
>
{!connectedTelegramAccount ? (
<Typography variant='subtitle1'>Connect with Telegram</Typography>
) : (
<Typography variant='subtitle1'>
Connected as {(connectedTelegramAccount.account as unknown as Partial<TelegramAccount>)?.username}
</Typography>
)}
<TelegramLoginIframe />
</>
</ConnectedAccount>
);
}

Expand Down
3 changes: 2 additions & 1 deletion components/settings/account/components/NewIdentityModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import { lowerCaseEqual } from 'lib/utils/strings';

import IdentityProviderItem from './IdentityProviderItem';
import { TELEGRAM_BOT_ID } from './TelegramLoginIframe';
import { TELEGRAM_BOT_ID, TelegramLoginIframe } from './TelegramLoginIframe';

const WarpcastLogin = dynamic(
() => import('components/login/components/WarpcastLogin').then((module) => module.WarpcastLogin),
Expand Down Expand Up @@ -106,7 +106,7 @@

useEffect(() => {
setAccountUpdatePaused(isOpen);
}, [isOpen]);

Check warning on line 109 in components/settings/account/components/NewIdentityModal.tsx

View workflow job for this annotation

GitHub Actions / Test apps

React Hook useEffect has a missing dependency: 'setAccountUpdatePaused'. Either include it or remove the dependency array

Check warning on line 109 in components/settings/account/components/NewIdentityModal.tsx

View workflow job for this annotation

GitHub Actions / Validate code

React Hook useEffect has a missing dependency: 'setAccountUpdatePaused'. Either include it or remove the dependency array

return (
<Modal
Expand Down Expand Up @@ -168,6 +168,7 @@
}}
>
Connect
<TelegramLoginIframe />
</Button>
</IdentityProviderItem>
)}
Expand Down
36 changes: 7 additions & 29 deletions components/settings/account/components/TelegramLoginIframe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,14 @@ export function loginWithTelegram(callback: (user: TelegramAccount) => void) {
window.Telegram.Login.auth({ bot_id: TELEGRAM_BOT_ID, request_access: true }, callback);
}

export class TelegramLoginIframe extends React.Component<{
widgetVersion?: string;
children?: React.ReactNode;
}> {
instance: HTMLDivElement | null = null;

componentDidMount() {
export function TelegramLoginIframe() {
const ref = React.useRef<HTMLDivElement>(null);
React.useEffect(() => {
const script = document.createElement('script');
script.src = `https://telegram.org/js/telegram-widget.js?${this.props.widgetVersion || ''}`;
script.src = 'https://telegram.org/js/telegram-widget.js?22';
script.async = true;
this.instance?.appendChild(script);
}
ref.current?.appendChild(script);
}, []);

render() {
return (
<div
style={{
cursor: 'pointer',
opacity: 0,
pointerEvents: 'none',
position: 'absolute',
width: 0,
height: 0
}}
ref={(component) => {
this.instance = component;
}}
>
{this.props.children}
</div>
);
}
return <div ref={ref} />;
}
Loading