From 592a6e097a62f748856fad53365aa24f7414e54b Mon Sep 17 00:00:00 2001 From: Ben Kremer Date: Thu, 9 Mar 2023 14:23:52 +0100 Subject: [PATCH] chore: fix missing prettier formatting --- dapps/react-dapp-v2/src/chains/index.ts | 4 +- dapps/react-dapp-v2/src/constants/default.ts | 10 +- .../src/contexts/JsonRpcContext.tsx | 96 ++++++++++--------- dapps/react-dapp-v2/src/helpers/api.ts | 4 +- dapps/react-dapp-v2/src/helpers/namespaces.ts | 2 +- dapps/react-dapp-v2/src/pages/index.tsx | 23 +++-- 6 files changed, 77 insertions(+), 62 deletions(-) diff --git a/dapps/react-dapp-v2/src/chains/index.ts b/dapps/react-dapp-v2/src/chains/index.ts index 31aaade..a49c852 100644 --- a/dapps/react-dapp-v2/src/chains/index.ts +++ b/dapps/react-dapp-v2/src/chains/index.ts @@ -6,7 +6,7 @@ import * as polkadot from "./polkadot"; import * as solana from "./solana"; import * as near from "./near"; import * as elrond from "./elrond"; -import * as tron from './tron'; +import * as tron from "./tron"; import { ChainMetadata, ChainRequestRender } from "../helpers"; @@ -25,7 +25,7 @@ export function getChainMetadata(chainId: string): ChainMetadata { return near.getChainMetadata(chainId); case "elrond": return elrond.getChainMetadata(chainId); - case 'tron': + case "tron": return tron.getChainMetadata(chainId); default: throw new Error(`No metadata handler for namespace ${namespace}`); diff --git a/dapps/react-dapp-v2/src/constants/default.ts b/dapps/react-dapp-v2/src/constants/default.ts index bb83a2c..cc6fc60 100644 --- a/dapps/react-dapp-v2/src/constants/default.ts +++ b/dapps/react-dapp-v2/src/constants/default.ts @@ -13,7 +13,7 @@ export const DEFAULT_MAIN_CHAINS = [ "solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ", "polkadot:91b171bb158e2d3848fa23a9f1c25182", "elrond:1", - 'tron:0x2b6653dc', + "tron:0x2b6653dc", ]; export const DEFAULT_TEST_CHAINS = [ @@ -27,7 +27,7 @@ export const DEFAULT_TEST_CHAINS = [ "polkadot:e143f23803ac50e8f6f8e62695d1ce9e", "near:testnet", "elrond:D", - 'tron:0xcd8690dc', + "tron:0xcd8690dc", ]; export const DEFAULT_CHAINS = [...DEFAULT_MAIN_CHAINS, ...DEFAULT_TEST_CHAINS]; @@ -118,9 +118,9 @@ export enum DEFAULT_ELROND_EVENTS {} /** * TRON */ - export enum DEFAULT_TRON_METHODS { - TRON_SIGN_TRANSACTION = 'tron_signTransaction', - TRON_SIGN_MESSAGE = 'tron_signMessage' +export enum DEFAULT_TRON_METHODS { + TRON_SIGN_TRANSACTION = "tron_signTransaction", + TRON_SIGN_MESSAGE = "tron_signMessage", } export enum DEFAULT_TRON_EVENTS {} diff --git a/dapps/react-dapp-v2/src/contexts/JsonRpcContext.tsx b/dapps/react-dapp-v2/src/contexts/JsonRpcContext.tsx index 7d4aee1..267210b 100644 --- a/dapps/react-dapp-v2/src/contexts/JsonRpcContext.tsx +++ b/dapps/react-dapp-v2/src/contexts/JsonRpcContext.tsx @@ -20,7 +20,7 @@ import { Transaction as SolanaTransaction, } from "@solana/web3.js"; // @ts-expect-error -import TronWeb from 'tronweb'; +import TronWeb from "tronweb"; import { eip712, formatTestTransaction, @@ -674,11 +674,14 @@ export function JsonRpcContextProvider({ specVersion: "0x00002468", transactionVersion: "0x0000000e", address: `${address}`, - blockHash: "0x554d682a74099d05e8b7852d19c93b527b5fae1e9e1969f6e1b82a2f09a14cc9", + blockHash: + "0x554d682a74099d05e8b7852d19c93b527b5fae1e9e1969f6e1b82a2f09a14cc9", blockNumber: "0x00cb539c", era: "0xc501", - genesisHash: "0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e", - method: "0x0001784920616d207369676e696e672074686973207472616e73616374696f6e21", + genesisHash: + "0xe143f23803ac50e8f6f8e62695d1ce9e4e1d68aa36c1cd2cfd15340213f3423e", + method: + "0x0001784920616d207369676e696e672074686973207472616e73616374696f6e21", nonce: "0x00000000", signedExtensions: [ "CheckNonZeroSender", @@ -688,11 +691,11 @@ export function JsonRpcContextProvider({ "CheckMortality", "CheckNonce", "CheckWeight", - "ChargeTransactionPayment" + "ChargeTransactionPayment", ], tip: "0x00000000000000000000000000000000", - version: 4 - } + version: 4, + }; try { const result = await client!.request<{ @@ -709,7 +712,7 @@ export function JsonRpcContextProvider({ }, }, }); - + return { method: DEFAULT_POLKADOT_METHODS.POLKADOT_SIGN_TRANSACTION, address, @@ -1056,35 +1059,41 @@ export function JsonRpcContextProvider({ ), }; - // -------- TRON RPC METHODS -------- + // -------- TRON RPC METHODS -------- const tronRpc = { testSignTransaction: _createJsonRpcRequestHandler( - async (chainId: string, address: string): Promise => { + async ( + chainId: string, + address: string + ): Promise => { // Nile TestNet, if you want to use in MainNet, change the fullHost to 'https://api.trongrid.io' - const fullHost = isTestnet ? "https://nile.trongrid.io/" : "https://api.trongrid.io/"; - + const fullHost = isTestnet + ? "https://nile.trongrid.io/" + : "https://api.trongrid.io/"; + const tronWeb = new TronWeb({ fullHost, - }) + }); - - // Take USDT as an example: + // Take USDT as an example: // Nile TestNet: https://nile.tronscan.org/#/token20/TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf // MainNet: https://tronscan.org/#/token20/TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t - - const testContract = isTestnet ? "TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf" : "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"; - const testTransaction = await tronWeb.transactionBuilder.triggerSmartContract( - testContract, - 'approve(address,uint256)', - { feeLimit: 200000000 }, - [ - { type: 'address', value: address }, - { type: 'uint256', value: 0 } - ], - address - ); + const testContract = isTestnet + ? "TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf" + : "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"; + const testTransaction = + await tronWeb.transactionBuilder.triggerSmartContract( + testContract, + "approve(address,uint256)", + { feeLimit: 200000000 }, + [ + { type: "address", value: address }, + { type: "uint256", value: 0 }, + ], + address + ); try { const { result } = await client!.request<{ result: any }>({ @@ -1094,18 +1103,18 @@ export function JsonRpcContextProvider({ method: DEFAULT_TRON_METHODS.TRON_SIGN_TRANSACTION, params: { address, - transaction:{ - ...testTransaction - } - } - } + transaction: { + ...testTransaction, + }, + }, + }, }); - + return { method: DEFAULT_TRON_METHODS.TRON_SIGN_TRANSACTION, address, valid: true, - result: result.signature + result: result.signature, }; } catch (error: any) { throw new Error(error); @@ -1113,9 +1122,11 @@ export function JsonRpcContextProvider({ } ), testSignMessage: _createJsonRpcRequestHandler( - async (chainId: string, address: string): Promise => { - - const message = 'This is a message to be signed for Tron'; + async ( + chainId: string, + address: string + ): Promise => { + const message = "This is a message to be signed for Tron"; try { const result = await client!.request<{ signature: string }>({ @@ -1125,25 +1136,24 @@ export function JsonRpcContextProvider({ method: DEFAULT_TRON_METHODS.TRON_SIGN_MESSAGE, params: { address, - message - } - } + message, + }, + }, }); return { method: DEFAULT_TRON_METHODS.TRON_SIGN_MESSAGE, address, valid: true, - result: result.signature + result: result.signature, }; } catch (error: any) { throw new Error(error); } } - ) + ), }; - return ( { - const namespace = chainId.split(":")[0]; - if (namespace !== 'eip155') { + const namespace = chainId.split(":")[0]; + if (namespace !== "eip155") { return { balance: "", symbol: "", name: "" }; } const ethChainId = chainId.split(":")[1]; diff --git a/dapps/react-dapp-v2/src/helpers/namespaces.ts b/dapps/react-dapp-v2/src/helpers/namespaces.ts index 1d6af6f..a91fc35 100644 --- a/dapps/react-dapp-v2/src/helpers/namespaces.ts +++ b/dapps/react-dapp-v2/src/helpers/namespaces.ts @@ -42,7 +42,7 @@ export const getSupportedMethodsByNamespace = (namespace: string) => { return Object.values(DEFAULT_NEAR_METHODS); case "elrond": return Object.values(DEFAULT_ELROND_METHODS); - case 'tron': + case "tron": return Object.values(DEFAULT_TRON_METHODS); default: throw new Error(`No default methods for namespace: ${namespace}`); diff --git a/dapps/react-dapp-v2/src/pages/index.tsx b/dapps/react-dapp-v2/src/pages/index.tsx index a9e1ac2..581e7f4 100644 --- a/dapps/react-dapp-v2/src/pages/index.tsx +++ b/dapps/react-dapp-v2/src/pages/index.tsx @@ -112,12 +112,12 @@ const Home: NextPage = () => { if (typeof client === "undefined") { throw new Error("WalletConnect is not initialized"); } - + await client.emit({ - topic: session?.topic || '', - event: { name: 'chainChanged', data: {} }, - chainId: 'eip155:5' - }) + topic: session?.topic || "", + event: { name: "chainChanged", data: {} }, + chainId: "eip155:5", + }); } const getEthereumActions = (): AccountAction[] => { @@ -297,12 +297,12 @@ const Home: NextPage = () => { return [ { method: DEFAULT_TRON_METHODS.TRON_SIGN_TRANSACTION, - callback: onSignTransaction + callback: onSignTransaction, }, { method: DEFAULT_TRON_METHODS.TRON_SIGN_MESSAGE, - callback: onSignMessage - } + callback: onSignMessage, + }, ]; }; @@ -420,7 +420,12 @@ const Home: NextPage = () => { return ( -
+
{isInitializing ? "Loading..." : renderContent()}