Skip to content

Commit

Permalink
Merge branch 'feature/evm' into pierregee/fix-hidden-chevron-on-addre…
Browse files Browse the repository at this point in the history
…ssbook
  • Loading branch information
Pierre Gee authored Oct 17, 2023
2 parents 1022c02 + 6294617 commit 7de1354
Show file tree
Hide file tree
Showing 9 changed files with 1,417 additions and 791 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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { DomainType, useDomainContext } from "@contexts/DomainContext";

export async function onShare(
address: string,
logger: NativeLoggingProps
logger: NativeLoggingProps,
): Promise<void> {
try {
await Share.share({
Expand Down Expand Up @@ -49,7 +49,7 @@ export function ReceiveScreen(): JSX.Element {
setShowToast(true);
setTimeout(() => setShowToast(false), TOAST_DURATION);
}, 500),
[showToast]
[showToast],
);

useEffect(() => {
Expand All @@ -74,7 +74,7 @@ export function ReceiveScreen(): JSX.Element {
>
{translate(
"screens/ReceiveScreen",
"Scan QR code to receive any dTokens (eg. DUSD,dBTC..) or DFI"
"Scan QR code to receive any dTokens (eg. DUSD,dBTC..) or DFI",
)}
</ThemedTextV2>

Expand Down Expand Up @@ -122,7 +122,7 @@ export function ReceiveScreen(): JSX.Element {
dark={tailwind("border-mono-dark-v2-300")}
light={tailwind("border-mono-light-v2-300")}
style={tailwind(
"py-4 mx-5 flex-row justify-center items-center border-b"
"py-4 mx-5 flex-row justify-center items-center border-b",
)}
>
<ThemedTextV2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function CreateWalletGuidelines({ navigation }: Props): JSX.Element {
>
{translate(
"screens/Guidelines",
"You will be shown 24 recovery words on the next screen. Keep your 24-word recovery safe as it will allow you to recover access to the wallet."
"You will be shown 24 recovery words on the next screen. Keep your 24-word recovery safe as it will allow you to recover access to the wallet.",
)}
</ThemedTextV2>
<LearnMoreCTA
Expand All @@ -105,7 +105,7 @@ export function CreateWalletGuidelines({ navigation }: Props): JSX.Element {
light={tailwind("bg-mono-light-v2-700")}
dark={tailwind("bg-mono-dark-v2-700")}
style={tailwind(
"flex h-6 w-6 flex-row items-center justify-center rounded-full mt-1"
"flex h-6 w-6 flex-row items-center justify-center rounded-full mt-1",
)}
>
{g.Icon?.()}
Expand Down Expand Up @@ -140,7 +140,7 @@ export function CreateWalletGuidelines({ navigation }: Props): JSX.Element {
>
{translate(
"screens/Guidelines",
"I understand it is my responsibility to keep my recovery words secure. Losing them will result in the irrecoverable loss of access to my wallet funds."
"I understand it is my responsibility to keep my recovery words secure. Losing them will result in the irrecoverable loss of access to my wallet funds.",
)}
</ThemedTextV2>
</ThemedTouchableOpacityV2>
Expand Down
Loading

0 comments on commit 7de1354

Please sign in to comment.