chore: fix missing prettier formatting

This commit is contained in:
Ben Kremer 2023-03-09 14:23:52 +01:00
parent 04b98ac68e
commit 592a6e097a
6 changed files with 77 additions and 62 deletions

View File

@ -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}`);

View File

@ -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 {}

View File

@ -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<IFormattedRpcResponse> => {
async (
chainId: string,
address: string
): Promise<IFormattedRpcResponse> => {
// 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<IFormattedRpcResponse> => {
const message = 'This is a message to be signed for Tron';
async (
chainId: string,
address: string
): Promise<IFormattedRpcResponse> => {
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 (
<JsonRpcContext.Provider
value={{

View File

@ -105,8 +105,8 @@ export async function apiGetAccountBalance(
address: string,
chainId: string
): Promise<AssetData> {
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];

View File

@ -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}`);

View File

@ -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 (
<SLayout>
<Column maxWidth={1000} spanHeight>
<Header ping={onPing} disconnect={disconnect} session={session} emit={emit}/>
<Header
ping={onPing}
disconnect={disconnect}
session={session}
emit={emit}
/>
<SContent>{isInitializing ? "Loading..." : renderContent()}</SContent>
</Column>
<Modal show={!!modal} closeModal={closeModal}>