Skip to content

Commit

Permalink
Merge pull request #73 from ton-connect/fix/platforms-field
Browse files Browse the repository at this point in the history
Fix/platforms field
  • Loading branch information
siandreev authored Aug 15, 2023
2 parents fe4c321 + e3c20f0 commit 01d4150
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 9 deletions.
10 changes: 10 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog @tonconnect/sdk

## [2.1.4](https://github.com/ton-connect/sdk/compare/sdk-2.1.3...sdk-2.1.4) (2023-08-15)


### Bug Fixes

* 'platform' field added to WalletInfo ([40e0332](https://github.com/ton-connect/sdk/commit/40e0332a37886baef6aaa9942a8fad7a2e29d78b))
* **sdk:** README updated ([900c115](https://github.com/ton-connect/sdk/commit/900c115bd71aa631026f60e55632e03d7b185784))



## [2.1.3](https://github.com/ton-connect/sdk/compare/sdk-2.1.2...sdk-2.1.3) (2023-04-03)


Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tonconnect/sdk",
"version": "2.1.3",
"version": "2.1.4",
"scripts": {
"build": "npx rimraf types-dist && npx rimraf lib && npx rollup -c rollup.config.mjs && ttsc --project tsconfig.declarations.json && api-extractor run && npx rimraf types-dist && npx rimraf dist && npx webpack --config webpack.config.js",
"test": "vitest run"
Expand Down
24 changes: 24 additions & 0 deletions packages/sdk/src/models/wallet/wallet-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ export interface WalletInfoBase {
* Info or landing page of your wallet. May be useful for TON newcomers.
*/
aboutUrl: string;

/**
* OS and browsers where the wallet could be installed
*/
platforms: (
| 'ios'
| 'android'
| 'macos'
| 'windows'
| 'linux'
| 'chrome'
| 'firefox'
| 'safari'
)[];
}

/**
Expand Down Expand Up @@ -99,6 +113,16 @@ export interface WalletInfoDTO {
tondns?: string;
about_url: string;
universal_url?: string;
platforms: (
| 'ios'
| 'android'
| 'macos'
| 'windows'
| 'linux'
| 'chrome'
| 'firefox'
| 'safari'
)[];

deepLink?: string;
bridge: (WalletInfoBridgeRemoteDTO | WalletInfoBridgeInjectedDTO)[];
Expand Down
3 changes: 2 additions & 1 deletion packages/sdk/src/provider/injected/injected-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export class InjectedProvider<T extends string = string> implements InternalProv
tondns: wallet.tonconnect.walletInfo.tondns,
jsBridgeKey,
injected: true,
embedded: wallet.tonconnect.isWalletBrowser
embedded: wallet.tonconnect.isWalletBrowser,
platforms: wallet.tonconnect.walletInfo.platforms
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { hasProperties, hasProperty } from 'src/utils/types';

export interface InjectedWalletApi {
deviceInfo: DeviceInfo;
walletInfo: Pick<WalletInfoDTO, 'name' | 'tondns' | 'image' | 'about_url'>;
walletInfo: Pick<WalletInfoDTO, 'name' | 'tondns' | 'image' | 'about_url' | 'platforms'>;
protocolVersion: number;
isWalletBrowser: boolean;
connect(protocolVersion: number, message: ConnectRequest): Promise<ConnectEvent>;
Expand All @@ -32,7 +32,12 @@ export function isJSBridgeWithMetadata(value: unknown): value is { tonconnect: I
return false;
}

return hasProperties(value.tonconnect.walletInfo, ['name', 'image', 'about_url']);
return hasProperties(value.tonconnect.walletInfo, [
'name',
'image',
'about_url',
'platforms'
]);
} catch {
return false;
}
Expand Down
80 changes: 77 additions & 3 deletions packages/sdk/src/resources/fallback-wallets-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export const FALLBACK_WALLETS_LIST: WalletInfoDTO[] = [
type: 'js',
key: 'tonkeeper'
}
]
],
platforms: ['ios', 'android', 'chrome', 'firefox']
},
{
name: 'OpenMask',
Expand All @@ -27,17 +28,90 @@ export const FALLBACK_WALLETS_LIST: WalletInfoDTO[] = [
type: 'js',
key: 'openmask'
}
]
],
platforms: ['chrome']
},
{
name: 'MyTonWallet',
image: 'https://mytonwallet.io/icon-256.png',
about_url: 'https://mytonwallet.io',
universal_url: 'https://connect.mytonwallet.org',
bridge: [
{
type: 'js',
key: 'mytonwallet'
},
{
type: 'sse',
url: 'https://tonconnectbridge.mytonwallet.org/bridge/'
}
],
platforms: ['chrome', 'windows', 'macos', 'linux']
},
{
name: 'Tonhub',
image: 'https://tonhub.com/tonconnect_logo.png',
about_url: 'https://tonhub.com',
universal_url: 'https://tonhub.com/ton-connect',
bridge: [
{
type: 'js',
key: 'tonhub'
},
{
type: 'sse',
url: 'https://connect.tonhubapi.com/tonconnect'
}
],
platforms: ['ios', 'android']
},
{
name: 'TonFlow',
image: 'https://tonflow.net/assets/images/tonflow_ico_192.png',
about_url: 'https://tonflow.net',
bridge: [
{
type: 'js',
key: 'tonflow'
}
],
platforms: ['chrome']
},
{
name: 'DeWallet',
image: 'https://app.delabwallet.com/logo_black.png',
about_url: 'https://delabwallet.com',
bridge: [
{
type: 'js',
key: 'dewallet'
}
],
platforms: ['chrome']
},
{
name: 'XTONWallet',
image: 'https://xtonwallet.com/assets/img/icon-256-back.png',
about_url: 'https://xtonwallet.com',
bridge: [
{
type: 'js',
key: 'xtonwallet'
}
],
platforms: ['chrome', 'firefox']
},
{
name: 'TON Wallet',
image: 'https://wallet.ton.org/assets/ui/qr-logo.png',
about_url:
'https://chrome.google.com/webstore/detail/ton-wallet/nphplpgoakhhjchkkhmiggakijnkhfnd',
bridge: [
{
type: 'js',
key: 'tonwallet'
}
]
],
platforms: ['chrome']
}
];
13 changes: 11 additions & 2 deletions packages/sdk/src/wallets-list-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ export class WalletsListManager {
name: walletConfigDTO.name,
imageUrl: walletConfigDTO.image,
aboutUrl: walletConfigDTO.about_url,
tondns: walletConfigDTO.tondns
tondns: walletConfigDTO.tondns,
platforms: walletConfigDTO.platforms
} as WalletInfo;

walletConfigDTO.bridge.forEach(bridge => {
Expand Down Expand Up @@ -165,11 +166,19 @@ export class WalletsListManager {
const containsName = 'name' in value;
const containsImage = 'image' in value;
const containsAbout = 'about_url' in value;
const containsPlatforms = 'platforms' in value;

if (!containsName || !containsImage || !containsAbout) {
if (!containsName || !containsImage || !containsAbout || !containsPlatforms) {
return false;
}

if (
!(value as { platforms: unknown }).platforms ||
!Array.isArray((value as { platforms: unknown }).platforms) ||
!(value as { platforms: string[] }).platforms.length
) {
return false;
}
if (
!('bridge' in value) ||
!Array.isArray((value as { bridge: unknown }).bridge) ||
Expand Down

0 comments on commit 01d4150

Please sign in to comment.