Skip to content
Open
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
2 changes: 1 addition & 1 deletion advanced/dapps/react-dapp-v2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"react-scripts": "^4.0.3",
"solana-wallet": "^1.0.1",
"styled-components": "^6.1.15",
"tronweb": "^4.4.0",
"tronweb": "^6.0.4",
"web-vitals": "^0.2.4"
},
"devDependencies": {
Expand Down
159 changes: 127 additions & 32 deletions advanced/dapps/react-dapp-v2/pnpm-lock.yaml

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions advanced/dapps/react-dapp-v2/src/chains/tron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ export const TronChainData: ChainsMap = {
export const TronMetadata: NamespaceMetadata = {
// Tron Mainnet
"0x2b6653dc": {
logo: "https://tronscan.io/static/media/TRON.4a760cebd163969b2ee874abf2415e9a.svg",
logo: "/assets/tron.png",
rgb: "183, 62, 49",
},
// Tron TestNet
"0xcd8690dc": {
logo: "https://tronscan.io/static/media/TRON.4a760cebd163969b2ee874abf2415e9a.svg",
logo: "/assets/tron.png",
rgb: "183, 62, 49",
},
};
Expand Down
3 changes: 3 additions & 0 deletions advanced/dapps/react-dapp-v2/src/components/Asset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const btcLogo = getChainMetadata(
"bip122:000000000933ea01ad0ee984209779ba"
).logo;
const suiLogo = getChainMetadata("sui:mainnet").logo;
const tronLogo = getChainMetadata("tron:0x2b6653dc").logo;
const SAsset = styled.div`
width: 100%;
padding: 20px;
Expand Down Expand Up @@ -55,6 +56,8 @@ function getAssetIcon(asset: AssetData): JSX.Element {
return <Icon src={btcLogo} />;
case "sui":
return <Icon src={suiLogo} />;
case "trx":
return <Icon src={tronLogo} />;
default:
return <Icon src={"/assets/eth20.svg"} />;
}
Expand Down
30 changes: 19 additions & 11 deletions advanced/dapps/react-dapp-v2/src/contexts/JsonRpcContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import {
Transaction as SolanaTransaction,
clusterApiUrl,
} from "@solana/web3.js";
// @ts-expect-error
import TronWeb from "tronweb";
import { TronWeb } from "tronweb";
import {
IPactCommand,
PactCommand,
Expand Down Expand Up @@ -1646,7 +1645,7 @@ export function JsonRpcContextProvider({
const testContract = isTestnet
? "TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf"
: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t";
const testTransaction =
const { transaction } =
await tronWeb.transactionBuilder.triggerSmartContract(
testContract,
"approve(address,uint256)",
Expand All @@ -1658,17 +1657,26 @@ export function JsonRpcContextProvider({
address
);

const result = await client!.request<{ signature: any }>({
const sessionProperties = session!.sessionProperties;
const isV1Method = sessionProperties?.tron_method_version === "v1";

const result = await client!.request<{
signature: any;
result?: { signature: any };
}>({
chainId,
topic: session!.topic,
request: {
method: DEFAULT_TRON_METHODS.TRON_SIGN_TRANSACTION,
params: {
address,
transaction: {
...testTransaction,
},
},
params: isV1Method
? {
address,
transaction,
}
: {
address,
transaction: { transaction },
},
},
});
console.log("tron sign transaction result", result);
Expand All @@ -1677,7 +1685,7 @@ export function JsonRpcContextProvider({
method: DEFAULT_TRON_METHODS.TRON_SIGN_TRANSACTION,
address,
valid: true,
result: result.signature,
result: result.result?.signature ?? result.signature,
};
}
),
Expand Down
49 changes: 49 additions & 0 deletions advanced/dapps/react-dapp-v2/src/helpers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AssetData } from "./types";
import { PactCommand } from "@kadena/client";
import { apiGetBip122AccountBalance } from "./bip122";
import { getSuiClient } from "./sui";
import { TronWeb } from "tronweb";

export type RpcProvidersByChainId = Record<
number,
Expand Down Expand Up @@ -165,6 +166,10 @@ export async function apiGetAccountBalance(
return apiGetSuiAccountBalance(address, chainId);
}

if (namespace === "tron") {
return apiGetTronAccountBalance(address, networkId);
}

if (namespace !== "eip155") {
return { balance: "", symbol: "", name: "" };
}
Expand All @@ -186,6 +191,50 @@ export async function apiGetAccountBalance(
return { balance, ...token };
}

export const apiGetTronAccountBalance = async (
address: string,
networkId: string
): Promise<AssetData> => {
try {

let fullHost: string;

switch (networkId) {
case "0x2b6653dc":
fullHost = 'https://api.trongrid.io';
break;
case "0x94a9059e":
fullHost = 'https://api.shasta.trongrid.io';
break;
case "0xcd8690dc":
fullHost = 'https://nile.trongrid.io';
break;
default:
fullHost = 'https://api.trongrid.io';
}

const tronWeb = new TronWeb({
fullHost: fullHost
});
const balance = await tronWeb.trx.getBalance(address);

const balanceInTrx = tronWeb.fromSun(balance);

return {
balance: balanceInTrx.toString(),
symbol: "TRX",
name: "TRX"
};
} catch (error) {
console.error("Failed to fetch TRON balance:", error);
return {
balance: "0",
symbol: "TRX",
name: "TRON"
};
}
};

export const apiGetSuiAccountBalance = async (
address: string,
chainId: string
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions advanced/wallets/react-wallet-v2/src/data/TronData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const TRON_MAINNET_CHAINS: TRONChains = {
'tron:0x2b6653dc': {
chainId: '0x2b6653dc',
name: 'Tron',
logo: 'https://tronscan.io/static/media/TRON.4a760cebd163969b2ee874abf2415e9a.svg',
logo: '/chain-logos/tron.png',
rgb: '183, 62, 49',
fullNode: 'https://api.trongrid.io',
namespace: 'tron'
Expand All @@ -34,7 +34,7 @@ export const TRON_TEST_CHAINS: TRONChains = {
'tron:0xcd8690dc': {
chainId: '0xcd8690dc',
name: 'Tron Testnet',
logo: 'https://tronscan.io/static/media/TRON.4a760cebd163969b2ee874abf2415e9a.svg',
logo: '/chain-logos/tron.png',
rgb: '183, 62, 49',
fullNode: 'https://nile.trongrid.io/',
namespace: 'tron'
Expand Down
3 changes: 2 additions & 1 deletion advanced/wallets/react-wallet-v2/src/lib/TronLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export default class TronLib {
}

public async signTransaction(transaction: any) {
const signedtxn = await this.tronWeb.trx.sign(transaction.transaction)
// Compatible with both new and old structures at the handler level
const signedtxn = await this.tronWeb.trx.sign(transaction)
return signedtxn
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export async function approveTronRequest(
return formatJsonRpcResult(id, res)

case TRON_SIGNING_METHODS.TRON_SIGN_TRANSACTION:
const signedTransaction = await wallet.signTransaction(request.params.transaction)
// Compatible with both new and old structures
// New structure : request.params.transaction = transaction
// Old structure: request.params.transaction = { transaction: transaction }
const transaction = request.params.transaction?.transaction || request.params.transaction;
const signedTransaction = await wallet.signTransaction(transaction)

return formatJsonRpcResult(id, signedTransaction)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,12 @@ export default function SessionProposalModal() {
let sessionProperties = {
capabilities: JSON.stringify(capabilities)
} as any

// Add TRON-specific properties if TRON namespace exists
if (namespaces.tron) {
sessionProperties["tron_method_version"] = "v1"
}

if (namespaces.bip122) {
const bip122Chain = namespaces.bip122.chains?.[0]!
sessionProperties.bip122_getAccountAddresses = JSON.stringify({
Expand Down