Skip to content

Commit

Permalink
Merge branch 'lyka/convert-screen-evm-balance' into pierregee/fix-con…
Browse files Browse the repository at this point in the history
…vert-screen
  • Loading branch information
lykalabrada authored Oct 10, 2023
2 parents e671459 + 04bf50e commit d483e30
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
4 changes: 2 additions & 2 deletions mobile-app/app/api/transaction/transfer_domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -65,8 +68,7 @@ export function TokenSelectionScreen(): JSX.Element {
const [isSearchFocus, setIsSearchFocus] = useState(false);
const searchRef = useRef<TextInput>();

const filteredTokensByDomain =
domain === DomainType.EVM ? tokens.filter((t) => !t.isLPS) : tokens;
const filteredTokensByDomain = domain === DomainType.EVM ? evmTokens : tokens;

const tokensWithBalance = getTokensWithBalance(
filteredTokensByDomain,
Expand Down
30 changes: 25 additions & 5 deletions shared/store/evmApi.ts
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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",
}),
}),
Expand All @@ -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",
Expand All @@ -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:
Expand All @@ -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;
Expand Down

0 comments on commit d483e30

Please sign in to comment.