Skip to content
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

Ton with temporal overwrite #562

Merged
merged 11 commits into from
Oct 4, 2024
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
26 changes: 13 additions & 13 deletions android/lib/src/main/res/raw/trust_min.js

Large diffs are not rendered by default.

Binary file modified bun.lockb
Binary file not shown.
10 changes: 10 additions & 0 deletions packages/android-web3-provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { ICosmosProviderConfig } from '@trustwallet/web3-provider-cosmos/types/C
import { IEthereumProviderConfig } from '@trustwallet/web3-provider-ethereum/types/EthereumProvider';
import { AptosProvider } from '@trustwallet/web3-provider-aptos';
import { IAptosProviderConfig } from '@trustwallet/web3-provider-aptos/types/AptosProvider';
import { TonBridge, TonProvider } from '@trustwallet/web3-provider-ton';
import { ITonProviderConfig } from '@trustwallet/web3-provider-ton/types/TonProvider';
import { ITonBridgeConfig } from '@trustwallet/web3-provider-ton/types/TonBridge';

const core = (strategy: AdapterStrategyType, handler?: IHandler) =>
new Web3Provider({ strategy, handler });
Expand All @@ -24,10 +27,17 @@ const ethereum = (config: IEthereumProviderConfig) =>

const aptos = (config: IAptosProviderConfig) => new AptosProvider(config);

const ton = (config: ITonProviderConfig) => new TonProvider(config);

const tonBridge = (config: ITonBridgeConfig, provider: TonProvider) =>
new TonBridge(config, provider);

window.trustwallet = {
core,
solana,
cosmos,
ethereum,
aptos,
ton,
tonBridge,
};
3 changes: 2 additions & 1 deletion packages/android-web3-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"@trustwallet/web3-provider-solana": "workspace:*",
"@trustwallet/web3-provider-cosmos": "workspace:*",
"@trustwallet/web3-provider-aptos": "workspace:*",
"@trustwallet/web3-provider-ton": "workspace:*",
"rollup-plugin-polyfill-node": "0.13.0"
},
"devDependencies": { }
"devDependencies": {}
}
1 change: 0 additions & 1 deletion packages/ios-web3-provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"dev": "bun build ./index.ts --outdir ./dist --watch"
},
"dependencies": {
"ton": "^13.9.0",
"@trustwallet/web3-provider-core": "workspace:*",
"@trustwallet/web3-provider-ethereum": "workspace:*",
"@trustwallet/web3-provider-solana": "workspace:*",
Expand Down
51 changes: 49 additions & 2 deletions packages/ios-web3-provider/swift/TrustWeb3Provider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,24 @@ public struct TrustWeb3Provider {
public let ethereum: EthereumConfig
public let solana: SolanaConfig
public let aptos: AptosConfig
public let ton: TonConfig
public let appVersion: String
public let autoConnect: Bool

public init(
ethereum: EthereumConfig,
solana: SolanaConfig,
aptos: AptosConfig = AptosConfig(network: "Mainnet", chainId: "1")
aptos: AptosConfig = AptosConfig(network: "Mainnet", chainId: "1"),
ton: TonConfig,
appVersion: String,
autoConnect: Bool
) {
self.ethereum = ethereum
self.solana = solana
self.aptos = aptos
self.ton = ton
self.appVersion = appVersion
self.autoConnect = autoConnect
}

public struct EthereumConfig: Equatable {
Expand All @@ -43,6 +52,11 @@ public struct TrustWeb3Provider {
}
}

public struct TonConfig: Equatable {
public init() {
}
}

public struct AptosConfig: Equatable {
public let network: String
public let chainId: String
Expand Down Expand Up @@ -113,13 +127,44 @@ public struct TrustWeb3Provider {
const solana = trustwallet.solana(config.solana);
const cosmos = trustwallet.cosmos();
const aptos = trustwallet.aptos(config.aptos);
const ton = trustwallet.ton();

const walletInfo = {
deviceInfo: {
platform: 'iphone',

// TODO: Change to trust
appName: 'OpenMask',
appVersion: "\(config.appVersion)",
maxProtocolVersion: 2,
features: [
'SendTransaction',
{
name: 'SendTransaction',
maxMessages: 4,
},
],
},
walletInfo: {
// TODO: Change to trust
name: 'OpenMask',
image: 'https://assets-cdn.trustwallet.com/dapps/trust.logo.png',
about_url: 'https://trustwallet.com/about-us',
},
isWalletBrowser: \(config.autoConnect),
};

core.registerProviders([ethereum, solana, cosmos, aptos].map(provider => {
const tonBridge = trustwallet.tonBridge(walletInfo, ton);

core.registerProviders([ethereum, solana, cosmos, aptos, ton].map(provider => {
provider.sendResponse = core.sendResponse.bind(core);
provider.sendError = core.sendError.bind(core);
return provider;
}));

// TODO: remove after updating to trust
window.openmask = { tonconnect: tonBridge, provider: ton };

// Custom methods
ethereum.emitChainChanged = (chainId) => {
ethereum.setChainId('0x' + parseInt(chainId || '1').toString(16));
Expand Down Expand Up @@ -151,10 +196,12 @@ public struct TrustWeb3Provider {
trustwallet.cosmos = cosmos;
trustwallet.TrustCosmos = trustwallet.cosmos;
trustwallet.aptos = aptos;
trustwallet.ton = ton;

window.ethereum = trustwallet.ethereum;
window.keplr = trustwallet.cosmos;
window.aptos = trustwallet.aptos;
window.ton = trustwallet.ton;

const getDefaultCosmosProvider = (chainId) => {
return trustwallet.cosmos.getOfflineSigner(chainId);
Expand Down
4 changes: 2 additions & 2 deletions packages/ios-web3-provider/swift/trust-min.js
Git LFS file not shown
8 changes: 7 additions & 1 deletion packages/ios-web3-provider/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"extends": "../../tsconfig.json",
"exclude": ["package.json", "rollup.config.js", "tsconfig.json", "tests", "./dist"],
"exclude": [
"package.json",
"rollup.config.js",
"tsconfig.json",
"tests",
"./dist"
],
"compilerOptions": {
"rootDir": "./",
"outDir": "./dist/types",
Expand Down
13 changes: 7 additions & 6 deletions packages/ton/MobileAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { TonProvider } from './TonProvider';
import { Address } from 'ton';

interface ITransaction {
valid_until: number;
Expand Down Expand Up @@ -27,9 +26,6 @@ export class MobileAdapter {
messages: (transaction?.messages || []).map(
({ state_init, ...message }) => ({
...message,
address: Address.parse(message.address).toString({
bounceable: false,
}),
stateInit: state_init,
}),
),
Expand Down Expand Up @@ -60,12 +56,17 @@ export class MobileAdapter {
return this.provider.internalRequest<T>('signMessage', params);

case 'ton_sendTransaction':
case 'tonConnect_sendTransaction':
return this.provider.internalRequest<T>(
case 'tonConnect_sendTransaction': {
const res = await this.provider.internalRequest<string>(
'signTransaction',
MobileAdapter.mapToCamelCase((params as object[])[0] as ITransaction),
);

const { nonce, hash } = JSON.parse(res);

return method === 'ton_sendTransaction' ? nonce : { boc: hash };
}

case 'ton_requestAccounts': {
const res = await this.provider.internalRequest<string>(
'requestAccounts',
Expand Down
9 changes: 9 additions & 0 deletions packages/ton/TonBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ export class TonBridge implements TonConnectBridge {
});
}

async disconnect() {
await this.provider.send('tonConnect_disconnect', {});

return this.emit({
event: 'disconnect',
payload: {},
});
}

/**
* Return and call callbacks
* @param event
Expand Down
4 changes: 1 addition & 3 deletions packages/ton/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
"build:source": "bun build:clean; rollup --config ./rollup.config.js; bun run build:types",
"dev": "bun build ./index.ts --outdir ./dist --watch"
},
"peerDependencies": {
"ton": "^13.9.0"
},
"peerDependencies": {},
"dependencies": {
"@trustwallet/web3-provider-core": "workspace:*"
}
Expand Down