Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

436 feature complete type checks on token transactions #459

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
49a3d57
fixed: type check for transaction functions
zzggo Feb 3, 2025
352b572
Merge branch 'dev' into 436-feature-complete-type-checks-on-token-tra…
zzggo Feb 4, 2025
1830175
Merge branch 'dev' into 436-feature-complete-type-checks-on-token-tra…
zzggo Feb 4, 2025
a9f60e1
Merge branch 'dev' into 436-feature-complete-type-checks-on-token-tra…
zzggo Feb 5, 2025
43d7ba4
Merge branch 'dev' into 436-feature-complete-type-checks-on-token-tra…
zzggo Feb 5, 2025
47362e4
Merge branch 'dev' into 436-feature-complete-type-checks-on-token-tra…
zzggo Feb 6, 2025
c2943a9
fixed: create transaction type and restructure the send folder
zzggo Feb 6, 2025
ae6c5e6
feat: set transaction state type
zzggo Feb 6, 2025
7f5451f
Merge branch 'dev' into 436-feature-complete-type-checks-on-token-tra…
zzggo Feb 7, 2025
c0afe2a
feat: check decimal places sending to env
zzggo Feb 7, 2025
1bd97ed
Merge branch 'dev' into 436-feature-complete-type-checks-on-token-tra…
zzggo Feb 7, 2025
e07a747
feat: set token transfer digit limits sending to flow
zzggo Feb 8, 2025
4b3858c
fixed: selected token default as flow, no null value allowed
zzggo Feb 8, 2025
3df9bfd
Merge branch 'dev' into 436-feature-complete-type-checks-on-token-tra…
zzggo Feb 9, 2025
7bcb3fb
feat: add decimal checks on move tokens
zzggo Feb 9, 2025
df6aa29
fixed: transaction ui update and change the function handler to globa…
zzggo Feb 10, 2025
7f6dbb2
Merge branch 'dev' into 436-feature-complete-type-checks-on-token-tra…
zzggo Feb 10, 2025
8c1e823
Merge branch 'dev' into 436-feature-complete-type-checks-on-token-tra…
zzggo Feb 11, 2025
37c5123
Merge branch 'dev' into 436-feature-complete-type-checks-on-token-tra…
zzggo Feb 11, 2025
44c9d57
Transaction reducer example
tombeckenham Feb 11, 2025
0b895f6
Scoped actions and removed imports
tombeckenham Feb 11, 2025
052f1a7
Corrected number entry and a couple of tests
tombeckenham Feb 12, 2025
f44f547
Merge pull request #498 from onflow:transaction-reducer
tombeckenham Feb 12, 2025
5a9740a
Updated Mapping to capitalize From To and moved TransferConfirmation …
tombeckenham Feb 12, 2025
d7712cb
Feat: add contact hook and store
zzggo Feb 12, 2025
f8177f9
feat: move the address list into store
zzggo Feb 12, 2025
35c98dd
feat: new web3 instance
zzggo Feb 12, 2025
b5104eb
Updated SendToEvm and confirmations
tombeckenham Feb 12, 2025
25c6c4e
Corrected address lookup redirect
tombeckenham Feb 12, 2025
5ec6f64
fixed: change to useContact, fixed the address check and rerendering …
zzggo Feb 12, 2025
18bf153
Merge branches '436-feature-complete-type-checks-on-token-transaction…
zzggo Feb 12, 2025
d93e6d4
EVM confirm in progress
tombeckenham Feb 12, 2025
4222512
Transitioned all send components to use reducer
tombeckenham Feb 13, 2025
266d59f
Changed routing structure for token sends
tombeckenham Feb 13, 2025
f13d4e7
Combined SendToEvm and SendToCadence
tombeckenham Feb 13, 2025
b0c5630
Consolidated all send functionality
tombeckenham Feb 13, 2025
6e963e9
feat: new contact card
zzggo Feb 13, 2025
67da668
Merge branch '436-feature-complete-type-checks-on-token-transactions'…
zzggo Feb 13, 2025
718209c
fixed: update profile with generic component passing in contact object
zzggo Feb 13, 2025
47c4f0e
fixed: move the set state out from component
zzggo Feb 13, 2025
7ac3ef9
fixed: select the store and set to a new object individually
zzggo Feb 13, 2025
bd907ee
Moved all the listen transaction stuff to the one function
tombeckenham Feb 13, 2025
a9b2a0a
Updating to call setAmount when changing tokens to adjust the decimals
tombeckenham Feb 13, 2025
93e6145
Removed value checking and manipulation from individual functions as …
tombeckenham Feb 13, 2025
76b61e1
Removed all the move FT stuff
tombeckenham Feb 13, 2025
b8dc375
Moved all transaction logic to the background 🎉
tombeckenham Feb 13, 2025
02b5ca5
Added tests for transaction reducer
tombeckenham Feb 13, 2025
1f5caa8
Merge branch 'dev' into 436-feature-complete-type-checks-on-token-tra…
tombeckenham Feb 13, 2025
982327a
Corrected some of the tests
tombeckenham Feb 13, 2025
0e243c4
Merge branch 'dev' into 436-feature-complete-type-checks-on-token-tra…
tombeckenham Feb 14, 2025
f4197fa
Removed code that altered values in wallet. Moved some code to number…
tombeckenham Feb 14, 2025
e5ab5be
Removed unused code and providers
tombeckenham Feb 14, 2025
3e7aaae
Removed temp code from webpack
tombeckenham Feb 14, 2025
0373993
Merge branch 'dev' into 436-feature-complete-type-checks-on-token-tra…
tombeckenham Feb 14, 2025
fc033ad
Returns empty string if empty string passed in
tombeckenham Feb 14, 2025
d05537a
Added metamask EOA address
tombeckenham Feb 14, 2025
36f8b03
fixed: return the contact card with icons first
zzggo Feb 14, 2025
f4e0bf4
Corrected evm transaction coversion to integer, and coin selector
tombeckenham Feb 14, 2025
ae3a72b
Merge remote-tracking branch 'refs/remotes/origin/436-feature-complet…
tombeckenham Feb 14, 2025
f95f71a
Corrected flow token coa transaction. Checks transaction amount in e2…
tombeckenham Feb 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ethErrors } from 'eth-rpc-errors';
import * as ethUtil from 'ethereumjs-util';
import { getApp } from 'firebase/app';
import { getAuth } from 'firebase/auth/web-extension';
import type { TokenInfo } from 'flow-native-token-registry';
import { encode } from 'rlp';
import web3, { TransactionError } from 'web3';

Expand Down Expand Up @@ -1935,11 +1936,11 @@ export class WalletController extends BaseController {

transferFTToEvmV2 = async (
vaultIdentifier: string,
amount = '1.0',
recipient
amount = '0.0',
recipient: string
): Promise<string> => {
await this.getNetwork();
const formattedAmount = parseFloat(amount).toFixed(8);
const formattedAmount = new BN(amount).decimalPlaces(8, BN.ROUND_DOWN).toString();

const script = await getScripts('bridge', 'bridgeTokensToEvmAddressV2');

Expand All @@ -1962,9 +1963,9 @@ export class WalletController extends BaseController {

transferFTFromEvm = async (
flowidentifier: string,
amount = '1.0',
amount: string,
receiver: string,
tokenResult
tokenResult: TokenInfo
): Promise<string> => {
await this.getNetwork();
const amountStr = amount.toString();
Expand Down Expand Up @@ -2001,9 +2002,9 @@ export class WalletController extends BaseController {
return txID;
};

withdrawFlowEvm = async (amount = '1.0', address: string): Promise<string> => {
withdrawFlowEvm = async (amount = '0.0', address: string): Promise<string> => {
await this.getNetwork();
const formattedAmount = parseFloat(amount).toFixed(8);
const formattedAmount = new BN(amount).decimalPlaces(8, BN.ROUND_DOWN).toString();
const script = await getScripts('evm', 'withdrawCoa');

const txID = await userWalletService.sendTransaction(script, [
Expand Down
1 change: 1 addition & 0 deletions src/ui/views/InnerRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { useWallet } from 'ui/utils';
import Deposit from '../views/Deposit';
import Enable from '../views/Enable';
import Send from '../views/Send';
//Transaction TODO: this is not used anymore, should be removed
import Swap from '../views/Swap';

import Dashboard from './Dashboard';
Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/Send/SendAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const SendAmount = () => {
const [coinList, setCoinList] = useState<CoinItem[]>([]);
const [isConfirmationOpen, setConfirmationOpen] = useState(false);
const [exceed, setExceed] = useState(false);
const [amount, setAmount] = useState<string | undefined>(undefined);
const [amount, setAmount] = useState<string>('0');
const [secondAmount, setSecondAmount] = useState('0.0');
const [validated, setValidated] = useState<any>(null);
const [userInfo, setUser] = useState<Contact>(USER_CONTACT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import IconNext from 'ui/FRWAssets/svg/next.svg';
import { LLSpinner, LLProfile, FRWProfile } from 'ui/FRWComponent';
import { useWallet } from 'ui/utils';

interface ToEthConfirmationProps {
interface EvmConfirmationProps {
isConfirmationOpen: boolean;
data: any;
handleCloseIconClicked: () => void;
handleCancelBtnClicked: () => void;
handleAddBtnClicked: () => void;
}

const ToEthConfirmation = (props: ToEthConfirmationProps) => {
const EvmToEvmConfirmation = (props: EvmConfirmationProps) => {
const usewallet = useWallet();
const history = useHistory();
const [sending, setSending] = useState(false);
Expand Down Expand Up @@ -84,8 +84,8 @@ const ToEthConfirmation = (props: ToEthConfirmationProps) => {
}, []);

const transferToken = useCallback(async () => {
const amount = props.data.amount * 1e18;
const network = await usewallet.getNetwork();
//Transaction TODO: tokeninfo getting directly from api using tokenSymbol, need to add filter on contractName and address
const tokenResult = await usewallet.openapi.getTokenInfo(props.data.tokenSymbol, network);

const amountStr = props.data.amount.toString();
Expand Down Expand Up @@ -375,4 +375,4 @@ const ToEthConfirmation = (props: ToEthConfirmationProps) => {
);
};

export default ToEthConfirmation;
export default EvmToEvmConfirmation;
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import CloseIcon from '@mui/icons-material/Close';
import InfoIcon from '@mui/icons-material/Info';
import { Box, Typography, Drawer, Stack, Grid, CardMedia, IconButton, Button } from '@mui/material';
import BN from 'bignumber.js';
import React, { useState, useEffect, useCallback } from 'react';
import { useHistory } from 'react-router-dom';

Expand All @@ -20,7 +21,7 @@ interface ToEthConfirmationProps {
handleAddBtnClicked: () => void;
}

const ToEthConfirmation = (props: ToEthConfirmationProps) => {
const FlowToEVMConfirmation = (props: ToEthConfirmationProps) => {
const wallet = useWallet();
const history = useHistory();
const [sending, setSending] = useState(false);
Expand Down Expand Up @@ -79,7 +80,7 @@ const ToEthConfirmation = (props: ToEthConfirmationProps) => {
}, []);

const transferFlow = useCallback(async () => {
const amount = parseFloat(props.data.amount).toFixed(8);
const amount = new BN(props.data.amount).decimalPlaces(8, BN.ROUND_DOWN).toString();

wallet
.transferFlowEvm(props.data.contact.address, amount)
Expand All @@ -106,17 +107,10 @@ const ToEthConfirmation = (props: ToEthConfirmationProps) => {
}, [history, props, wallet]);

const transferFt = useCallback(async () => {
const amount = props.data.amount * 1e18;
setSending(true);
// TB: I don't know why this is needed
const encodedData = props.data.erc20Contract.methods
.transfer(props.data.contact.address, amount)
.encodeABI();

const tokenResult = await wallet.openapi.getTokenInfo(props.data.tokenSymbol);
// Note that gas is not used in this function
const gas = '1312d00';
const value = parseFloat(props.data.amount).toFixed(8);
const data = encodedData;
const value = new BN(props.data.amount).decimalPlaces(8, BN.ROUND_DOWN).toString();

const address = tokenResult!.address.startsWith('0x')
? tokenResult!.address.slice(2)
Expand Down Expand Up @@ -389,4 +383,4 @@ const ToEthConfirmation = (props: ToEthConfirmationProps) => {
);
};

export default ToEthConfirmation;
export default FlowToEVMConfirmation;
9 changes: 5 additions & 4 deletions src/ui/views/Send/SendEth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import { useWallet } from 'ui/utils';
import CancelIcon from '../../../../components/iconfont/IconClose';
import TransferAmount from '../TransferAmount';

import EvmConfirmation from './EvmConfirmation';
import ToEthConfirmation from './ToEthConfirmation';
import EvmToEvmConfirmation from './EvmToEvmConfirmation';
import FlowToEVMConfirmation from './FlowToEVMConfirmation';

interface ContactState {
contact: Contact;
}
Expand Down Expand Up @@ -304,7 +305,7 @@ const SendEth = () => {
</Button>
</Box>
{childType === 'evm' ? (
<EvmConfirmation
<EvmToEvmConfirmation
isConfirmationOpen={isConfirmationOpen}
data={{
contact: location.state.contact,
Expand All @@ -322,7 +323,7 @@ const SendEth = () => {
}}
/>
) : (
<ToEthConfirmation
<FlowToEVMConfirmation
isConfirmationOpen={isConfirmationOpen}
data={{
contact: location.state.contact,
Expand Down
65 changes: 37 additions & 28 deletions src/ui/views/Send/TransferConfirmation.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import CloseIcon from '@mui/icons-material/Close';
import InfoIcon from '@mui/icons-material/Info';
import { Box, Typography, Drawer, Stack, Grid, CardMedia, IconButton, Button } from '@mui/material';
import BN from 'bignumber.js';
import React, { useState, useEffect, useCallback } from 'react';
import { useHistory } from 'react-router-dom';

Expand Down Expand Up @@ -55,6 +56,7 @@ const TransferConfirmation = (props: TransferConfirmationProps) => {
'#41CC5D',
'#41CC5D',
];

const startCount = useCallback(() => {
let count = 0;
let intervalId;
Expand Down Expand Up @@ -82,17 +84,35 @@ const TransferConfirmation = (props: TransferConfirmationProps) => {
setOccupied(false);
}, []);

const transferToken = async () => {
// TODO: Replace it with real data
if (props.data.childType === 'evm') {
withDrawEvm();
return;
} else if (props.data.childType) {
sendFromChild();
return;
const runTransaction = async () => {
setSending(true);
try {
if (props.data.childType === 'evm') {
await handleEvmTransfer();
} else if (props.data.childType) {
await tokenFromChild();
} else {
await transferTokenOnCadence();
}
} catch {
setFailed(true);
} finally {
setSending(false);
}
};

const handleEvmTransfer = async () => {
if (props.data.tokenSymbol.toLowerCase() === 'flow') {
await flowFromEvm();
} else {
await otherFTFromEvm();
}
};

const transferTokenOnCadence = async () => {
setSending(true);
const amount = parseFloat(props.data.amount).toFixed(8);
const amount = new BN(props.data.amount).decimalPlaces(8, BN.ROUND_DOWN).toString();

wallet
.transferInboxTokens(props.data.tokenSymbol, props.data.contact.address, amount)
.then(async (txID) => {
Expand All @@ -117,8 +137,9 @@ const TransferConfirmation = (props: TransferConfirmationProps) => {
});
};

const sendFromChild = async () => {
const amount = parseFloat(props.data.amount).toFixed(8);
const tokenFromChild = async () => {
const amount = new BN(props.data.amount).decimalPlaces(8, BN.ROUND_DOWN).toString();

wallet
.sendFTfromChild(
props.data.userContact.address,
Expand Down Expand Up @@ -149,21 +170,9 @@ const TransferConfirmation = (props: TransferConfirmationProps) => {
});
};

const withDrawEvm = async () => {
console.log('transferToken ->', props.data);
setSending(true);
if (props.data.tokenSymbol.toLowerCase() === 'flow') {
transferFlow();
} else {
transferFt();
}
};

const transferFlow = async () => {
const amount = parseFloat(props.data.amount).toFixed(8);
// const txID = await wallet.transferTokens(props.data.tokenSymbol, props.data.contact.address, amount);
const flowFromEvm = async () => {
wallet
.withdrawFlowEvm(amount, props.data.contact.address)
.withdrawFlowEvm(props.data.amount, props.data.contact.address)
.then(async (txID) => {
await wallet.setRecent(props.data.contact);
wallet.listenTransaction(
Expand All @@ -185,7 +194,7 @@ const TransferConfirmation = (props: TransferConfirmationProps) => {
});
};

const transferFt = async () => {
const otherFTFromEvm = async () => {
const tokenResult = await wallet.openapi.getEvmTokenInfo(props.data.tokenSymbol);
console.log('tokenResult ', tokenResult, props.data.amount);

Expand All @@ -194,7 +203,7 @@ const TransferConfirmation = (props: TransferConfirmationProps) => {
tokenResult!['flowIdentifier'],
props.data.amount,
props.data.contact.address,
tokenResult
tokenResult!
)
.then(async (txID) => {
await wallet.setRecent(props.data.contact);
Expand Down Expand Up @@ -396,7 +405,7 @@ const TransferConfirmation = (props: TransferConfirmationProps) => {
/>

<Button
onClick={transferToken}
onClick={runTransaction}
disabled={sending || occupied}
variant="contained"
color="success"
Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/Send/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ const Send = () => {
isLoading={isLoading}
handleClick={(eachgroup) => {
const isEvmAddress = isValidEthereumAddress(eachgroup.address);

//Transaction TODO: make these two routes and components structure match
const pathname = isEvmAddress
? '/dashboard/wallet/sendeth'
: '/dashboard/wallet/sendAmount';
Expand Down
Loading