diff --git a/mobile-app/app/api/transaction/transfer_domain.ts b/mobile-app/app/api/transaction/transfer_domain.ts index 5f2a762055..9468a86fd3 100644 --- a/mobile-app/app/api/transaction/transfer_domain.ts +++ b/mobile-app/app/api/transaction/transfer_domain.ts @@ -12,6 +12,7 @@ import { fromAddress, Eth } from "@defichain/jellyfish-address"; import { NetworkName } from "@defichain/jellyfish-network"; import { ConvertDirection } from "@screens/enum"; import { parseUnits } from "ethers/lib/utils"; +import { getEthRpcUrl } from "@store/evmApi"; import TransferDomainV1 from "../../contracts/TransferDomainV1.json"; const TD_CONTRACT_ADDR = "0xdf00000000000000000000000000000000000001"; @@ -222,8 +223,7 @@ async function createSignedEvmTx({ data = tdFace.encodeFunctionData("transferDST20", transferDST20); } - // TODO: Make ETH RPC URL dynamic based on network - const ethRpc = new providers.JsonRpcProvider("http://localhost:19551"); // TODO: Get Eth rpc url based on network + const ethRpc = new providers.JsonRpcProvider(await getEthRpcUrl()); const wallet = new ethers.Wallet(privateKey); /* TODO: Figure out CORS issue when using the ethRpc */ diff --git a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/TokenSelectionScreen.tsx b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/TokenSelectionScreen.tsx index a38e6d64f7..98d7c4e935 100644 --- a/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/TokenSelectionScreen.tsx +++ b/mobile-app/app/screens/AppNavigator/screens/Portfolio/screens/TokenSelectionScreen.tsx @@ -32,6 +32,7 @@ import { PortfolioParamList } from "../PortfolioNavigator"; import { ActiveUSDValueV2 } from "../../Loans/VaultDetail/components/ActiveUSDValueV2"; import { TokenIcon } from "../components/TokenIcon"; import { TokenNameText } from "../components/TokenNameText"; +import { useEvmTokenBalances } from "../hooks/EvmTokenBalances"; export interface TokenSelectionItem extends BottomSheetToken { usdAmount: BigNumber; @@ -57,6 +58,8 @@ export function TokenSelectionScreen(): JSX.Element { const tokens = useSelector((state: RootState) => tokensSelector(state.wallet), ); + const { evmTokens } = useEvmTokenBalances(); + const { hasFetchedToken } = useSelector((state: RootState) => state.wallet); const [searchString, setSearchString] = useState(""); const { getTokenPrice } = useTokenPrice(); @@ -65,8 +68,7 @@ export function TokenSelectionScreen(): JSX.Element { const [isSearchFocus, setIsSearchFocus] = useState(false); const searchRef = useRef(); - const filteredTokensByDomain = - domain === DomainType.EVM ? tokens.filter((t) => !t.isLPS) : tokens; + const filteredTokensByDomain = domain === DomainType.EVM ? evmTokens : tokens; const tokensWithBalance = getTokensWithBalance( filteredTokensByDomain, diff --git a/shared/store/evmApi.ts b/shared/store/evmApi.ts index 2bd7d97548..a5eba6f375 100644 --- a/shared/store/evmApi.ts +++ b/shared/store/evmApi.ts @@ -1,5 +1,6 @@ import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react"; import { EnvironmentNetwork } from "@waveshq/walletkit-core"; +import { SecuredStoreAPI } from "@api"; export const evmApi = createApi({ reducerPath: "evmApi", @@ -10,7 +11,7 @@ export const evmApi = createApi({ { network: EnvironmentNetwork; evmAddress: string } >({ query: ({ network = EnvironmentNetwork.TestNet, evmAddress }) => ({ - url: `${getEthRpcUrl(network)}/api/v2/addresses/${evmAddress}`, + url: `${getBlockscoutUrl(network)}/api/v2/addresses/${evmAddress}`, method: "GET", }), }), @@ -19,7 +20,7 @@ export const evmApi = createApi({ { network: EnvironmentNetwork; evmAddress: string } >({ query: ({ network = EnvironmentNetwork.TestNet, evmAddress }) => ({ - url: `${getEthRpcUrl( + url: `${getBlockscoutUrl( network, )}/api/v2/addresses/${evmAddress}/token-balances`, method: "GET", @@ -33,13 +34,14 @@ export const { useGetEvmTokenBalancesMutation, } = evmApi; -const getEthRpcUrl = (network: EnvironmentNetwork) => { - // TODO: Add proper ethereum RPC URLs for each network +const getBlockscoutUrl = (network: EnvironmentNetwork) => { + // TODO: Add proper blockscout url for each network switch (network) { case EnvironmentNetwork.LocalPlayground: case EnvironmentNetwork.RemotePlayground: case EnvironmentNetwork.DevNet: - return "http://34.22.222.153:4000"; + case EnvironmentNetwork.Changi: + return "http://34.87.158.111:4000"; // TODO: add final blockscout url for playground and devnet case EnvironmentNetwork.TestNet: return "https://blockscout.changi.ocean.jellyfishsdk.com"; case EnvironmentNetwork.MainNet: @@ -48,6 +50,24 @@ const getEthRpcUrl = (network: EnvironmentNetwork) => { } }; +export const getEthRpcUrl = async () => { + const network = await SecuredStoreAPI.getNetwork(); + // TODO: Add proper ethereum RPC URLs for each network + switch (network) { + case EnvironmentNetwork.LocalPlayground: + return "http://localhost:19551"; + case EnvironmentNetwork.RemotePlayground: + case EnvironmentNetwork.DevNet: + case EnvironmentNetwork.Changi: + return "http://34.34.156.49:20551"; // TODO: add final eth rpc url for changi, devnet and remote playground + case EnvironmentNetwork.TestNet: + return "https://changi.dfi.team"; // TODO: add final eth rpc url for testnet, with proper domain name + case EnvironmentNetwork.MainNet: + default: + return "https://changi.dfi.team"; // TODO: add final eth rpc url for mainnet, with proper domain name + } +}; + interface EvmToken { address: string; decimals: string;