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

Handle bin parameter in transfer links #312

Merged
merged 2 commits into from
Nov 25, 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
4 changes: 4 additions & 0 deletions packages/core/src/service/deeplinkingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ export function parseTonTransferWithAddress(options: { url: string }) {
}
}

if (data.query.bin) {
throw new Error('Unsupported link');
}

const result: Omit<TonTransferParams, 'address'> & { address: string } = {
address: linkAddress,
...data.query
Expand Down
59 changes: 33 additions & 26 deletions packages/uikit/src/components/connect/connectHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,47 +20,54 @@ import { sendEventToBridge } from '@tonkeeper/core/dist/service/tonConnect/httpB
import { useAppSdk } from '../../hooks/appSdk';
import { useTranslation } from '../../hooks/translation';
import { QueryKey } from '../../libs/queryKey';
import { useActiveAccountQuery, useActiveWallet } from '../../state/wallet';
import { useActiveAccountQuery } from '../../state/wallet';
import { BLOCKCHAIN_NAME } from '@tonkeeper/core/dist/entries/crypto';
import { useToast } from '../../hooks/useNotification';

export const useGetConnectInfo = () => {
const sdk = useAppSdk();
const { t } = useTranslation();
const notifyError = useToast();

return useMutation<null | TonConnectParams, Error, string>(async url => {
const transfer = parseTonTransferWithAddress({ url });
try {
const transfer = parseTonTransferWithAddress({ url });

if (transfer) {
sdk.uiEvents.emit('copy', {
method: 'copy',
id: Date.now(),
params: t('loading')
});

sdk.uiEvents.emit('transfer', {
method: 'transfer',
id: Date.now(),
params: { chain: BLOCKCHAIN_NAME.TON, ...transfer, from: 'qr-code' }
});
return null;
}

const params = parseTonConnect({ url });

if (typeof params === 'string') {
console.error(params);
throw new Error('Unsupported link');
}

// TODO: handle auto connect

if (transfer) {
sdk.uiEvents.emit('copy', {
method: 'copy',
id: Date.now(),
params: t('loading')
});

sdk.uiEvents.emit('transfer', {
method: 'transfer',
id: Date.now(),
params: { chain: BLOCKCHAIN_NAME.TON, ...transfer, from: 'qr-code' }
});
return null;
}

const params = parseTonConnect({ url });

if (typeof params === 'string') {
console.error(params);
return null;
return params;
} catch (e) {
notifyError(String(e));
throw e;
}

// TODO: handle auto connect

sdk.uiEvents.emit('copy', {
method: 'copy',
id: Date.now(),
params: t('loading')
});

return params;
});
};

Expand Down
1 change: 0 additions & 1 deletion packages/uikit/src/hooks/useNotification.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useQueryClient } from '@tanstack/react-query';
import { useTranslation } from './translation';
import { useCallback, useEffect } from 'react';
import { notifyError } from '../components/transfer/common';
Expand Down
Loading