Skip to content

Commit

Permalink
Merge pull request #312 from tonkeeper/fix/transfer-bin
Browse files Browse the repository at this point in the history
Handle bin parameter in transfer links
  • Loading branch information
KuznetsovNikita authored Nov 25, 2024
2 parents 99cdf18 + 13b9c26 commit 9d373be
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
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

0 comments on commit 9d373be

Please sign in to comment.