Skip to content

Commit

Permalink
fix(chore): fixed ios/android loading issue (#4066)
Browse files Browse the repository at this point in the history
* fixed TextEncoder error

* fixed loading issue

* removed text-encoding

* fixed wrong balance issue

* fix 9 decimal points on transfer domain

* fix package and mobile expo

---------

Co-authored-by: pierregee <[email protected]>
  • Loading branch information
fullstackninja864 and pierregee authored Oct 17, 2023
1 parent 2b49ffd commit 6294617
Show file tree
Hide file tree
Showing 6 changed files with 871 additions and 404 deletions.
3 changes: 0 additions & 3 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ module.exports = function (api) {
},
],
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-transform-private-methods",
"@babel/plugin-transform-class-properties",
"@babel/plugin-transform-private-property-in-object",
"react-native-reanimated/plugin",
];

Expand Down
10 changes: 5 additions & 5 deletions mobile-app/app/api/transaction/transfer_domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { Prevout } from "@defichain/jellyfish-transaction-builder";
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 TransferDomainV1 from "@shared-contracts/TransferDomainV1.json";

const TD_CONTRACT_ADDR = "0xdf00000000000000000000000000000000000001";
Expand Down Expand Up @@ -272,8 +271,10 @@ async function createSignedEvmTx({
const tdFace = new utils.Interface(TransferDomainV1.abi);
const from = isEvmToDvm ? evmAddress : TD_CONTRACT_ADDR;
const to = isEvmToDvm ? TD_CONTRACT_ADDR : evmAddress;
// TODO: round off parsedAmount to 8 decimals
const parsedAmount = parseUnits(amount.toString(), 18); // TODO: Get decimals from token contract
const parsedAmount = utils.parseUnits(
amount.decimalPlaces(8, BigNumber.ROUND_DOWN).toString(),
18,
); // TODO: Get decimals from token contract
const vmAddress = dvmAddress;

if (sourceTokenId === "0" || targetTokenId === "0") {
Expand All @@ -289,7 +290,6 @@ async function createSignedEvmTx({
}
const wallet = new ethers.Wallet(privateKey);

/* TODO: Figure out CORS issue when using the ethRpc */
const tx: providers.TransactionRequest = {
to: TD_CONTRACT_ADDR,
nonce,
Expand All @@ -315,7 +315,7 @@ function stripEvmSuffixFromTokenId(tokenId: string) {
* Get DST20 contract address
* https://github.com/DeFiCh/ain/blob/f5a671362f9899080d0a0dddbbcdcecb7c19d9e3/lib/ain-contracts/src/lib.rs#L79
*/
function getAddressFromDST20TokenId(tokenId: number): string {
export function getAddressFromDST20TokenId(tokenId: number | string): string {
const parsedTokenId = BigInt(tokenId);
const numberStr = parsedTokenId.toString(16); // Convert parsedTokenId to hexadecimal
const paddedNumberStr = numberStr.padStart(38, "0"); // Pad with zeroes to the left
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useEffect, useState } from "react";
import { formatEther, formatUnits } from "viem";
import { WalletToken, useNetworkContext } from "@waveshq/walletkit-ui";
import { utils } from "ethers";
import { batch, useSelector } from "react-redux";
Expand All @@ -11,6 +10,7 @@ import { useAppDispatch } from "@hooks/useAppDispatch";
import { fetchEvmWalletDetails, fetchEvmTokenBalances } from "@store/evm";
import { useEVMProvider } from "@contexts/EVMProvider";
import { useIsFocused } from "@react-navigation/native";
import { getAddressFromDST20TokenId } from "@api/transaction/transfer_domain";

interface AssociatedToken {
[key: string]: TokenData;
Expand Down Expand Up @@ -54,9 +54,9 @@ export function useEvmTokenBalances(): { evmTokens: WalletToken[] } {
avatarSymbol: "DFI",
};
try {
const evmDfiBalance = formatEther(
BigInt(evmWalletDetails?.coin_balance ?? 0),
);
const evmDfiBalance = utils
.formatEther(evmWalletDetails?.coin_balance ?? "0")
.toString();
dfiToken.amount = evmDfiBalance;
setEvmTokens(
evmTokenBalances.reduce(
Expand All @@ -76,10 +76,9 @@ export function useEvmTokenBalances(): { evmTokens: WalletToken[] } {
name: `${tokenDetails.name} for EVM`,
displaySymbol: tokenDetails.displaySymbol,
avatarSymbol: tokenDetails.symbol,
amount: formatUnits(
BigInt(each.value),
+each?.token?.decimals,
),
amount: utils
.formatUnits(each.value, each?.token?.decimals)
.toString(),
},
];
}
Expand Down Expand Up @@ -121,11 +120,3 @@ export function useEvmTokenBalances(): { evmTokens: WalletToken[] } {

return { evmTokens };
}

export function getAddressFromDST20TokenId(tokenId: string): string {
const parsedTokenId = BigInt(tokenId);
const numberStr = parsedTokenId.toString(16); // Convert parsedTokenId to hexadecimal
const paddedNumberStr = numberStr.padStart(38, "0"); // Pad with zeroes to the left
const finalStr = `ff${paddedNumberStr}`;
return utils.getAddress(finalStr);
}
Loading

0 comments on commit 6294617

Please sign in to comment.