Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/old-dragons-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ton/walletkit': patch
---

Make bridge SSE connection optional for sending messages
1 change: 1 addition & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"fix-jetton-param-naming",
"late-cups-argue",
"move-domain-from-signer-to-wallets",
"old-dragons-hear",
"rename-transaction-action-to-send",
"short-kings-flow",
"smart-toys-remain",
Expand Down
6 changes: 6 additions & 0 deletions packages/appkit-react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @ton/appkit-react

## 0.0.6-alpha.3

### Patch Changes

- @ton/appkit@0.0.5-alpha.3

## 0.0.6-alpha.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/appkit-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ton/appkit-react",
"version": "0.0.6-alpha.2",
"version": "0.0.6-alpha.3",
"type": "module",
"scripts": {
"build": "pnpm run build:esm && pnpm run copy:css",
Expand Down
7 changes: 7 additions & 0 deletions packages/appkit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @ton/appkit

## 0.0.5-alpha.3

### Patch Changes

- Updated dependencies [0042cc9]
- @ton/walletkit@0.0.12-alpha.3

## 0.0.5-alpha.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/appkit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ton/appkit",
"version": "0.0.5-alpha.2",
"version": "0.0.5-alpha.3",
"description": "",
"repository": {
"type": "git",
Expand Down
7 changes: 7 additions & 0 deletions packages/mcp/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @ton/mcp

## 0.1.15-alpha.15

### Patch Changes

- Updated dependencies [0042cc9]
- @ton/walletkit@0.0.12-alpha.3

## 0.1.15-alpha.14

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/mcp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ton/mcp",
"version": "0.1.15-alpha.14",
"version": "0.1.15-alpha.15",
"description": "TON MCP Server - Model Context Protocol server for TON blockchain wallet operations",
"license": "MIT",
"type": "module",
Expand Down
1 change: 1 addition & 0 deletions packages/walletkit-ios-bridge/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ window.initWalletKit = async (configuration, storage, bridgeTransport, sessionMa
eventProcessor: configuration.eventsConfiguration,
storage: storage ? new SwiftStorageAdapter(storage) : new MemoryStorageAdapter({}),
dev: configuration.dev,
analytics: configuration.analytics,
});

console.log('🚀 WalletKit iOS Bridge starting...');
Expand Down
5 changes: 4 additions & 1 deletion packages/walletkit-ios-bridge/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ export interface SwiftWalletSigner {
publicKey: () => Hex;
}

type ReusedTonWalletKitOptions = Pick<TonWalletKitOptions, 'deviceInfo' | 'walletManifest' | 'bridge' | 'dev'>;
type ReusedTonWalletKitOptions = Pick<
TonWalletKitOptions,
'deviceInfo' | 'walletManifest' | 'bridge' | 'dev' | 'analytics'
>;

export interface SwiftWalletKitConfiguration extends ReusedTonWalletKitOptions {
networkConfigurations?: {
Expand Down
6 changes: 6 additions & 0 deletions packages/walletkit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @ton/walletkit

## 0.0.12-alpha.3

### Patch Changes

- 0042cc9: Make bridge SSE connection optional for sending messages

## 0.0.12-alpha.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/walletkit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ton/walletkit",
"version": "0.0.12-alpha.2",
"version": "0.0.12-alpha.3",
"description": "Wallet kit for TON Connect",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
Expand Down
59 changes: 36 additions & 23 deletions packages/walletkit/src/core/BridgeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class BridgeManager {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private eventQueue: any[] = [];
private isProcessing = false;
private isActive = false;

// Durable events support
private eventStore: EventStore;
Expand Down Expand Up @@ -98,6 +99,23 @@ export class BridgeManager {
this.walletKitConfig = walletKitConfig;
this.jsBridgeTransport = config?.jsBridgeTransport;

if (this.config.bridgeUrl && !this.config.disableHttpConnection) {
this.bridgeProvider = new BridgeProvider<WalletConsumer>(
this.config.bridgeUrl,
this.queueBridgeEvent.bind(this),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(error: any) => {
log.error('Bridge listener error', { error: error.toString() });
// Send bridge-client-connect-error event for listener errors
this.analytics?.emitBridgeClientConnectError({
error_message: `${error?.toString() || 'Unknown error'}${error?.errorCode ? ` (Code: ${error?.errorCode})` : ''}`,
trace_id: error?.traceId,
client_id: error?.clientId,
});
},
);
}

if (!this.jsBridgeTransport && config?.enableJsBridge) {
throw new WalletKitError(ERROR_CODES.INVALID_CONFIG, 'JS Bridge transport is not configured');
}
Expand All @@ -107,8 +125,15 @@ export class BridgeManager {
* Initialize bridge connection
*/
async start(): Promise<void> {
if (this.bridgeProvider) {
log.warn('Bridge already initialized');
if (this.isActive === true) {
log.warn('Bridge already started');
return;
}

this.isActive = true;

if (this.isConnected === true) {
log.warn('Bridge already connected');
return;
}

Expand All @@ -121,6 +146,7 @@ export class BridgeManager {
this.reconnectAttempts = 0;
}
} catch (error) {
this.isActive = false;
log.error('Failed to start bridge', { error });
throw error;
}
Expand Down Expand Up @@ -321,14 +347,14 @@ export class BridgeManager {
async close(): Promise<void> {
if (this.bridgeProvider) {
await this.bridgeProvider.close();
this.bridgeProvider = undefined;
}

// Clear event queue and reset processing state
this.eventQueue = [];
this.isProcessing = false;

// this.sessions.clear();
this.isActive = false;
this.isConnected = false;
this.reconnectAttempts = 0;
if (this.requestProcessingTimeoutId) {
Expand Down Expand Up @@ -365,8 +391,11 @@ export class BridgeManager {
* Connect to TON Connect bridge
*/
private async connectToSSEBridge(): Promise<void> {
if (!this.config.bridgeUrl) {
return;
if (!this.bridgeProvider) {
throw new WalletKitError(
ERROR_CODES.BRIDGE_NOT_INITIALIZED,
'Bridge not initialized before connecting to SSE',
);
}

const connectTraceId = uuidv7();
Expand All @@ -390,24 +419,8 @@ export class BridgeManager {
});
}

this.bridgeProvider = await BridgeProvider.open<WalletConsumer>({
bridgeUrl: this.config.bridgeUrl,
clients,
listener: this.queueBridgeEvent.bind(this),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
errorListener: (error: any) => {
log.error('Bridge listener error', { error: error.toString() });
// Send bridge-client-connect-error event for listener errors
this.analytics?.emitBridgeClientConnectError({
error_message: `${error?.toString() || 'Unknown error'}${error?.errorCode ? ` (Code: ${error?.errorCode})` : ''}`,
trace_id: error?.traceId ?? connectTraceId,
client_id: error?.clientId,
});
},
options: {
lastEventId: this.lastEventId,
// heartbeatReconnectIntervalMs: this.config.reconnectInterval,
},
await this.bridgeProvider?.restoreConnection(clients, {
lastEventId: this.lastEventId,
});
this.isConnected = true;
this.reconnectAttempts = 0;
Expand Down
Loading