-
Notifications
You must be signed in to change notification settings - Fork 147
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
Feat/required features #324
base: feat/extra-currency
Are you sure you want to change the base?
Changes from all commits
e49e7ab
3ba0c46
eec8699
4e2c5b1
24d33df
ee96df4
20b914a
58619ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
node_modules | ||
dist | ||
.idea | ||
.vscode | ||
.DS_Store |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { UserRejectsError } from 'src/errors/protocol/events/connect/user-rejects.error'; | ||
export { MissingRequiredFeaturesError } from 'src/errors/protocol/events/connect/missing-required-features.error'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { DeviceInfo } from '@tonconnect/protocol'; | ||
import { TonConnectError } from 'src/errors/ton-connect.error'; | ||
|
||
/** | ||
* Thrown when wallet can't get manifest by passed manifestUrl. | ||
*/ | ||
export class MissingRequiredFeaturesError extends TonConnectError { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe need use generic for device |
||
declare cause: { | ||
device: DeviceInfo; | ||
}; | ||
|
||
protected get info(): string { | ||
return 'Missing required features. You need to update your wallet.'; | ||
} | ||
|
||
constructor(...args: ConstructorParameters<typeof TonConnectError>) { | ||
super(...args); | ||
|
||
Object.setPrototypeOf(this, MissingRequiredFeaturesError.prototype); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
import { Feature } from '@tonconnect/protocol'; | ||
import { IStorage } from 'src/storage/models/storage.interface'; | ||
import { EventDispatcher } from 'src/tracker/event-dispatcher'; | ||
import { SdkActionEvent } from 'src/tracker/types'; | ||
import { RequireFeature } from './wallet'; | ||
|
||
/** | ||
* TonConnect constructor options | ||
|
@@ -35,6 +37,8 @@ export interface TonConnectOptions { | |
*/ | ||
walletsListCacheTTLMs?: number; | ||
|
||
walletsRequiredFeatures?: RequireFeature[] | ((features: Feature[]) => boolean); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add descriptioins |
||
|
||
/** | ||
* Allows to disable auto pause/unpause SSE connection on 'document.visibilitychange' event. It is not recommended to change default behaviour. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export type RequireFeature = RequireSendTransactionFeature | RequireSignDataFeature | ||
|
||
export type RequireSendTransactionFeature = { | ||
name: 'SendTransaction'; | ||
minMessages?: number; | ||
extraCurrencyRequired?: boolean; | ||
}; | ||
|
||
export type RequireSignDataFeature = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove signData |
||
name: 'SignData'; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import { Feature } from "@tonconnect/protocol"; | ||
|
||
/** | ||
* Common information for injectable and http-compatible wallets. | ||
*/ | ||
|
@@ -27,6 +29,16 @@ export interface WalletInfoBase { | |
*/ | ||
aboutUrl: string; | ||
|
||
/** | ||
* List of features supported by the wallet. | ||
*/ | ||
features?: Feature[]; | ||
|
||
/** | ||
* Indicates if the wallet supports required features. | ||
*/ | ||
isSupportRequiredFeatures: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check in UIWalletList, for injected wallets |
||
|
||
/** | ||
* OS and browsers where the wallet could be installed | ||
*/ | ||
|
@@ -119,6 +131,7 @@ export interface WalletInfoDTO { | |
tondns?: string; | ||
about_url: string; | ||
universal_url?: string; | ||
features?: Feature[]; | ||
platforms: ( | ||
| 'ios' | ||
| 'android' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import { ManifestNotFoundError } from 'src/errors/protocol/events/connect/manife | |
import { TonConnectError } from 'src/errors/ton-connect.error'; | ||
import { UnknownError } from 'src/errors/unknown.error'; | ||
import { CONNECT_EVENT_ERROR_CODES, ConnectEventError } from '@tonconnect/protocol'; | ||
import { MissingRequiredFeaturesError } from 'src/errors/protocol/events/connect/missing-required-features.error'; | ||
|
||
const connectEventErrorsCodes: Partial<Record<CONNECT_EVENT_ERROR_CODES, typeof TonConnectError>> = | ||
{ | ||
|
@@ -12,18 +13,16 @@ const connectEventErrorsCodes: Partial<Record<CONNECT_EVENT_ERROR_CODES, typeof | |
[CONNECT_EVENT_ERROR_CODES.BAD_REQUEST_ERROR]: BadRequestError, | ||
[CONNECT_EVENT_ERROR_CODES.UNKNOWN_APP_ERROR]: UnknownAppError, | ||
[CONNECT_EVENT_ERROR_CODES.MANIFEST_NOT_FOUND_ERROR]: ManifestNotFoundError, | ||
[CONNECT_EVENT_ERROR_CODES.MANIFEST_CONTENT_ERROR]: ManifestContentErrorError | ||
[CONNECT_EVENT_ERROR_CODES.MANIFEST_CONTENT_ERROR]: ManifestContentErrorError, | ||
[CONNECT_EVENT_ERROR_CODES.MISSING_REQUIRED_FEATURES]: MissingRequiredFeaturesError | ||
}; | ||
|
||
class ConnectErrorsParser { | ||
parseError(error: ConnectEventError['payload']): TonConnectError { | ||
let ErrorConstructor: typeof TonConnectError = UnknownError; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move to another function |
||
const ErrorConstructor = connectEventErrorsCodes[error.code] ?? UnknownError; | ||
const options = "device" in error ? { cause: { device: error.device } } : undefined; | ||
|
||
if (error.code in connectEventErrorsCodes) { | ||
ErrorConstructor = connectEventErrorsCodes[error.code] || UnknownError; | ||
} | ||
|
||
return new ErrorConstructor(error.message); | ||
return new ErrorConstructor(error.message, options); | ||
} | ||
} | ||
|
||
|
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 changes in protocolo