-
Notifications
You must be signed in to change notification settings - Fork 37
feat: migrated tonconnect to the hub #1344
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
base: next
Are you sure you want to change the base?
Conversation
389b1ea to
59d7c07
Compare
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| export type ProviderAPI = Record<string, any>; | ||
|
|
||
| export type ConnectOptions = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove it since it's not being using.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 2ccb6c1
| @@ -0,0 +1,2 @@ | |||
| export const CAIP_NAMESPACE = 'ton'; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change it according to CAIP
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 8dddf18
501dbde to
74a5840
Compare
| return async (context) => { | ||
| const tonInstance = getInstance(); | ||
| await tonInstance.disconnect(); | ||
| commonActions.disconnect(context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do it separately in a and added to its action builder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 7ee58a7
| const disconnect = new ActionBuilder<TonActions, 'disconnect'>('disconnect') | ||
| .action(tonActions.disconnect(tonConnect)) | ||
| .after(changeAccountCleanup) | ||
| .build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use disconnect from common builders
| const changeAccountSubscriber = (getInstance: () => TonConnectUI) => | ||
| new ChangeAccountSubscriberBuilder< | ||
| ConnectedWallet | null, | ||
| TonConnectUI, | ||
| TonActions | ||
| >() | ||
| .getInstance(getInstance) | ||
| /* | ||
| * TON wallets don't implement account change events, and we can only listen to disconnect events | ||
| * by checking the payload value. | ||
| * More info: https://github.com/ton-blockchain/ton-connect/blob/main/wallet-guidelines.md | ||
| */ | ||
| .onSwitchAccount(async (event, context) => { | ||
| event.preventDefault(); | ||
| if (!event.payload) { | ||
| commonActions.disconnect(context); | ||
| } | ||
| }) | ||
| .format(async () => []) | ||
| .addEventListener((instance, callback) => { | ||
| return instance.onStatusChange(callback); | ||
| }) | ||
| .removeEventListener(() => { | ||
| /* | ||
| * We handle unsubscribing in the builder and by returning an unsubscribe function from 'addEventListener' | ||
| */ | ||
| }); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use change account subscriber builder for disconnect use another disconnect handler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 7ee58a7
| ): FunctionWithContext<TonActions['disconnect'], Context> { | ||
| return async (context) => { | ||
| const tonInstance = getInstance(); | ||
| await tonInstance.disconnect(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check if it's been disconnected don't disconnect again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 7ee58a7
# Conflicts: # wallets/core/package.json # wallets/core/src/hub/provider/types.ts # wallets/react/src/hub/helpers.ts # wallets/readme.md # Conflicts: # wallets/provider-all/src/index.ts # wallets/readme.md
20aafa5 to
21647c9
Compare
21647c9 to
64f5f2b
Compare
Summary
Added Ton builders, utils and types to the wallets core.
Migrated TonConnect to use the new hub APIs for ton namespaces and updated documentation:
How did you test this change?
TonConnect was tested end-to-end within the Hub environment:
Checklist: