Skip to content

Commit 5108307

Browse files
authored
Add tron wallet connection integration (#842)
* Add tron adapter
1 parent 212d534 commit 5108307

27 files changed

+7706
-8849
lines changed

.changeset/tiny-rings-help.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@relayprotocol/relay-tron-wallet-adapter': minor
3+
'@relayprotocol/relay-sdk': minor
4+
'@relayprotocol/relay-kit-ui': minor
5+
---
6+
7+
Add Tron adapter and balance logic

demo/context/walletFilter.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, { createContext, useContext, useState, ReactNode } from 'react'
22

33
interface WalletFilterContextState {
4-
walletFilter?: 'EVM' | 'SOL' | 'ECLIPSE' | 'BTC' | 'SUI'
4+
walletFilter?: 'EVM' | 'SOL' | 'ECLIPSE' | 'BTC' | 'SUI' | 'TRON'
55
setWalletFilter: (
6-
value: 'EVM' | 'SOL' | 'BTC' | 'ECLIPSE' | 'SUI' | undefined
6+
value: 'EVM' | 'SOL' | 'BTC' | 'ECLIPSE' | 'SUI' | 'TRON' | undefined
77
) => void
88
}
99

@@ -15,7 +15,7 @@ export const WalletFilterProvider: React.FC<{ children: ReactNode }> = ({
1515
children
1616
}) => {
1717
const [walletFilter, setWalletFilter] = useState<
18-
'EVM' | 'SOL' | 'ECLIPSE' | 'BTC' | 'SUI' | undefined
18+
'EVM' | 'SOL' | 'ECLIPSE' | 'BTC' | 'SUI' | 'TRON' | undefined
1919
>(undefined)
2020

2121
return (

demo/package.json

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@
1414
"trailingComma": "none"
1515
},
1616
"dependencies": {
17-
"@dynamic-labs-connectors/abstract-global-wallet-evm": "4.3.1",
18-
"@dynamic-labs/bitcoin": "4.22.2",
19-
"@dynamic-labs/eclipse": "4.22.2",
20-
"@dynamic-labs/ethereum": "4.22.2",
21-
"@dynamic-labs/ethereum-core": "4.22.2",
22-
"@dynamic-labs/sdk-react-core": "4.22.2",
23-
"@dynamic-labs/solana": "4.22.2",
24-
"@dynamic-labs/sui": "4.22.2",
25-
"@dynamic-labs/utils": "4.22.2",
26-
"@dynamic-labs/wagmi-connector": "4.22.2",
17+
"@dynamic-labs-connectors/abstract-global-wallet-evm": "4.4.3",
18+
"@dynamic-labs/bitcoin": "4.40.2",
19+
"@dynamic-labs/eclipse": "4.40.2",
20+
"@dynamic-labs/ethereum": "4.40.2",
21+
"@dynamic-labs/ethereum-core": "4.40.2",
22+
"@dynamic-labs/sdk-react-core": "4.40.2",
23+
"@dynamic-labs/solana": "4.40.2",
24+
"@dynamic-labs/sui": "4.40.2",
25+
"@dynamic-labs/tron": "4.40.2",
26+
"@dynamic-labs/utils": "4.40.2",
27+
"@dynamic-labs/wagmi-connector": "4.40.2",
2728
"@moonpay/moonpay-react": "^1.8.3",
2829
"@privy-io/cross-app-connect": "0.2.2",
2930
"@radix-ui/colors": "^0.1.8",
@@ -33,6 +34,7 @@
3334
"@relayprotocol/relay-sdk": "workspace:*",
3435
"@relayprotocol/relay-sui-wallet-adapter": "workspace:*",
3536
"@relayprotocol/relay-svm-wallet-adapter": "workspace:*",
37+
"@relayprotocol/relay-tron-wallet-adapter": "workspace:*",
3638
"@solana/web3.js": "~1.98.2",
3739
"@tanstack/react-query": "^5.20.2",
3840
"@types/node": "^22.5.4",
@@ -42,6 +44,7 @@
4244
"porto": "^0.0.85",
4345
"react": "^19.0.0",
4446
"react-dom": "^19.0.0",
47+
"tronweb": "^6.0.4",
4548
"usehooks-ts": "^3.1.0",
4649
"viem": ">=2.26.0",
4750
"wagmi": "^2.15.6"

demo/pages/_app.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { EIP1193RequestFn, fallback, Transport } from 'viem'
3030
import { chainIdToAlchemyNetworkMap } from 'utils/chainIdToAlchemyNetworkMap'
3131
import { useWalletFilter, WalletFilterProvider } from 'context/walletFilter'
3232
import { EclipseWalletConnectors } from '@dynamic-labs/eclipse'
33+
import { TronWalletConnectors } from '@dynamic-labs/tron'
3334
import { AbstractEvmWalletConnectors } from '@dynamic-labs-connectors/abstract-global-wallet-evm'
3435
import { MoonPayProvider } from 'context/MoonpayProvider'
3536
import { queryRelayChains } from '@relayprotocol/relay-kit-hooks'
@@ -142,7 +143,8 @@ const AppWrapper: FC<AppWrapperProps> = ({ children, dynamicChains }) => {
142143
BitcoinWalletConnectors,
143144
EclipseWalletConnectors,
144145
SuiWalletConnectors,
145-
AbstractEvmWalletConnectors
146+
AbstractEvmWalletConnectors,
147+
TronWalletConnectors
146148
],
147149
cssOverrides: `
148150
[data-testid="send-balance-button"] {

demo/pages/ui/swap.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@ import { isEclipseWallet } from '@dynamic-labs/eclipse'
3232
import { type Token } from '@relayprotocol/relay-kit-ui'
3333
import { isSuiWallet, SuiWallet } from '@dynamic-labs/sui'
3434
import { adaptSuiWallet } from '@relayprotocol/relay-sui-wallet-adapter'
35+
import { adaptTronWallet } from '@relayprotocol/relay-tron-wallet-adapter'
3536
import Head from 'next/head'
37+
import { isTronWallet, TronWallet } from '@dynamic-labs/tron'
3638

37-
const WALLET_VM_TYPES = ['evm', 'bvm', 'svm', 'suivm'] as const
39+
const WALLET_VM_TYPES = ['evm', 'bvm', 'svm', 'suivm', 'tvm'] as const
3840

3941
const SwapWidgetPage: NextPage = () => {
4042
useDynamicEvents('walletAdded', (newWallet) => {
@@ -170,6 +172,15 @@ const SwapWidgetPage: NextPage = () => {
170172
return executionResult
171173
}
172174
)
175+
} else if (isTronWallet(primaryWallet)) {
176+
const tronWeb = (primaryWallet as TronWallet).getTronWeb()
177+
if (!tronWeb) {
178+
throw 'Unable to setup Tron wallet'
179+
}
180+
adaptedWallet = adaptTronWallet(
181+
(primaryWallet as TronWallet).address,
182+
tronWeb
183+
)
173184
}
174185

175186
setWallet(adaptedWallet)
@@ -293,6 +304,8 @@ const SwapWidgetPage: NextPage = () => {
293304
setWalletFilter('ECLIPSE')
294305
} else if (chain?.vmType === 'suivm') {
295306
setWalletFilter('SUI')
307+
} else if (chain?.vmType === 'tvm') {
308+
setWalletFilter('TRON')
296309
} else {
297310
setWalletFilter(undefined)
298311
}

demo/utils/dynamic.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,16 @@ export const extractWalletIcon = (wallet: Wallet) => {
5454
export const convertToLinkedWallet = (wallet: Wallet): LinkedWallet => {
5555
const walletIcon = extractWalletIcon(wallet)
5656
let walletChain = wallet.chain.toLowerCase()
57-
let vmType: 'evm' | 'svm' | 'bvm' | 'suivm' = 'evm'
57+
let vmType: 'evm' | 'svm' | 'bvm' | 'suivm' | 'tvm' = 'evm'
5858

5959
if (walletChain === 'sol' || walletChain === 'eclipse') {
6060
vmType = 'svm'
6161
} else if (walletChain === 'btc') {
6262
vmType = 'bvm'
6363
} else if (walletChain === 'sui') {
6464
vmType = 'suivm'
65+
} else if (walletChain === 'tron') {
66+
vmType = 'tvm'
6567
}
6668

6769
const address =

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"build:ui": "pnpm run -C packages/ui build",
2424
"build:hooks": "pnpm run -C packages/hooks build",
2525
"build:sdk": "pnpm run -C packages/sdk build",
26-
"build:adapter": "pnpm run -C packages/relay-ethers-wallet-adapter build && pnpm run -C packages/relay-svm-wallet-adapter build && pnpm run -C packages/relay-bitcoin-wallet-adapter build && pnpm run -C packages/relay-sui-wallet-adapter build",
26+
"build:adapter": "pnpm run -C packages/relay-ethers-wallet-adapter build && pnpm run -C packages/relay-svm-wallet-adapter build && pnpm run -C packages/relay-bitcoin-wallet-adapter build && pnpm run -C packages/relay-sui-wallet-adapter build && pnpm run -C packages/relay-tron-wallet-adapter build",
2727
"syncSdkTypes": "node packages/sdk/scripts/sync-api.mjs",
2828
"sdk": "pnpm run -C packages/sdk dev",
2929
"typecheck": "tsc --noEmit",

packages/relay-tron-wallet-adapter/CHANGELOG.md

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<h3 align="center">Relay Tron Wallet Adapter</h3>
2+
3+
### Installation
4+
5+
```
6+
yarn add @relayprotocol/relay-tron-wallet-adapter @relayprotocol/relay-sdk
7+
```
8+
9+
Also make sure to install the peer dependencies required by the adapter if your application doesn't already include them:
10+
11+
```
12+
yarn add viem @relayprotocol/relay-sdk tronweb
13+
```
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
{
2+
"name": "@relayprotocol/relay-tron-wallet-adapter",
3+
"version": "0.0.0",
4+
"description": "A Tron adapter for use in @relayprotocol/relay-sdk",
5+
"type": "module",
6+
"source": "./src/index.ts",
7+
"main": "./_cjs/src/index.js",
8+
"module": "./_esm/src/index.js",
9+
"types": "./_types/src/index.d.ts",
10+
"typings": "./_types/src/index.d.ts",
11+
"sideEffects": false,
12+
"files": [
13+
"./_cjs",
14+
"./_esm",
15+
"./_types"
16+
],
17+
"exports": {
18+
"types": "./_types/src/index.d.ts",
19+
"import": "./_esm/src/index.js",
20+
"require": "./_cjs/src/index.js"
21+
},
22+
"scripts": {
23+
"build": "pnpm run clean && pnpm run build:cjs && pnpm run build:esm && pnpm run build:types",
24+
"build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./_cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./_cjs/package.json",
25+
"build:esm": "tsc --project ./tsconfig.build.json --module es2015 --outDir ./_esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./_esm/package.json",
26+
"build:types": "tsc --project ./tsconfig.build.json --module esnext --outDir ./_types --declarationDir ./_types --emitDeclarationOnly --declaration --declarationMap",
27+
"dev": "concurrently \"pnpm run clean\" \"pnpm run dev:esm\" \"pnpm run dev:types\"",
28+
"dev:esm": "tsc --watch --project ./tsconfig.build.json --module es2015 --outDir ./_esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./_esm/package.json",
29+
"dev:types": "tsc --watch --project ./tsconfig.build.json --module esnext --outDir ./_types --declarationDir ./_types --emitDeclarationOnly --declaration --declarationMap",
30+
"clean": "rimraf ./_esm ./_cjs ./_types",
31+
"typecheck": "tsc --noEmit"
32+
},
33+
"repository": {
34+
"type": "git",
35+
"url": "https://github.com/reservoirprotocol/relay-sdk"
36+
},
37+
"keywords": [
38+
"reservoir",
39+
"relay-tvm-wallet-adapter",
40+
"relay-tron-wallet-adapter",
41+
"reservoir-tron-wallet-adapter",
42+
"relay",
43+
"protocol",
44+
"sdk-adapter",
45+
"tvm",
46+
"tron"
47+
],
48+
"publishConfig": {
49+
"access": "public"
50+
},
51+
"devDependencies": {
52+
"rimraf": "^5.0.5"
53+
},
54+
"dependencies": {
55+
"@types/node": "^22.5.4",
56+
"axios": "^1.6.5"
57+
},
58+
"peerDependencies": {
59+
"@relayprotocol/relay-sdk": "workspace:*",
60+
"viem": ">=2.26.0",
61+
"tronweb": "^6.0.4"
62+
}
63+
}

0 commit comments

Comments
 (0)