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

chore: update wallet-ui to match new getTransactions rpc format #459

Merged
merged 43 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
77f4b7b
feat: add stark scan client
stanleyyconsensys Sep 2, 2024
6b7a5e2
chore: add starkscan config
stanleyyconsensys Sep 2, 2024
3c9a523
chore: lint
stanleyyconsensys Sep 2, 2024
576f302
chore: add interface
stanleyyconsensys Sep 2, 2024
19fdf56
Merge branch 'main' into feat/add-stark-scan-client
stanleyyconsensys Sep 5, 2024
5d446cb
chore: support multiple txn
stanleyyconsensys Sep 5, 2024
3dbdf32
chore: update starkscan
stanleyyconsensys Sep 5, 2024
924ea45
chore: update stark scan client
stanleyyconsensys Sep 6, 2024
bcf34c7
chore: update contract func name
stanleyyconsensys Sep 6, 2024
d1ad70c
chore: fix test
stanleyyconsensys Sep 6, 2024
1a061d3
chore: update data client
stanleyyconsensys Sep 6, 2024
3bda85f
Merge branch 'main' into feat/add-stark-scan-client
stanleyyconsensys Sep 6, 2024
114ea6d
Merge branch 'main' into feat/add-stark-scan-client
stanleyyconsensys Oct 22, 2024
7539056
Merge branch 'main' into feat/add-stark-scan-client
stanleyyconsensys Dec 2, 2024
ed699ff
chore: re-structure starkscan type
stanleyyconsensys Dec 2, 2024
93adb36
chore: add test coverage
stanleyyconsensys Dec 2, 2024
dadb493
chore: factory and config
stanleyyconsensys Dec 2, 2024
b21a5d2
chore: add backward compatibility for transactions type
stanleyyconsensys Dec 2, 2024
07f0232
chore: add comment
stanleyyconsensys Dec 2, 2024
7a26c70
chore: lint
stanleyyconsensys Dec 2, 2024
804a2bd
chore: resolve review comment
stanleyyconsensys Dec 4, 2024
8e9e163
chore: change dataVersion to enum
stanleyyconsensys Dec 4, 2024
b09361f
chore: lint
stanleyyconsensys Dec 4, 2024
7cbd66f
chore: update test helper and refactor ContractAddressFilter
stanleyyconsensys Dec 5, 2024
f657422
chore: lint
stanleyyconsensys Dec 5, 2024
4ee01bc
chore: add test for dataVersion filter
stanleyyconsensys Dec 5, 2024
3a99e76
chore: update txn state mgr test
stanleyyconsensys Dec 5, 2024
38e5d63
chore: update search condition
stanleyyconsensys Dec 5, 2024
63e3030
chore: update starkscan to handle missing selector_name
stanleyyconsensys Dec 5, 2024
6391e81
Merge branch 'feat/add-stark-scan-client' into chore/refactor-txn-mgr
stanleyyconsensys Dec 5, 2024
873a1de
Merge branch 'main' into chore/refactor-txn-mgr
khanti42 Dec 5, 2024
97f0e05
Merge branch 'main' into chore/revamp-list-transactions
stanleyyconsensys Dec 5, 2024
956b10e
chore: apply starkscan for list transaction
stanleyyconsensys Dec 6, 2024
29f7c5f
chore: update list transactions handle
stanleyyconsensys Dec 6, 2024
9dba1a9
chore: resolve comment
stanleyyconsensys Dec 9, 2024
33fe98e
chore: update wallet-ui to handle new starkNet_getTransactions
khanti42 Dec 11, 2024
4503cc9
Merge branch 'feat/refactor-list-transactions-with-starkscan' into ch…
khanti42 Dec 11, 2024
6ef547c
chore: rename type
khanti42 Dec 11, 2024
e864f26
chore: remove unecessary input param
khanti42 Dec 11, 2024
364ec70
chore: remove unecessary input param
khanti42 Dec 11, 2024
7d66f83
chore: change explorer link to starkscan
khanti42 Dec 11, 2024
87ff473
chore: fix comments
khanti42 Dec 11, 2024
3e950f5
Merge branch 'feat/refactor-list-transactions-with-starkscan' into ch…
khanti42 Dec 11, 2024
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Meta } from '@storybook/react';
import { Transaction } from 'types';
import { Transaction, TransactionStatus } from 'types';
import { TransactionListItemView } from './TransactionListItem.view';

export default {
Expand All @@ -12,18 +12,30 @@ const transaction: Transaction = {
txnType: 'invoke',
chainId: '0x534e5f5345504f4c4941',
senderAddress:
'0x05ccc9fc2d7ce9e2b0f2cee1a4b898570bb4d03ba23ad6f72f0db971bd04552c',
'0x5ccc9fc2d7ce9e2b0f2cee1a4b898570bb4d03ba23ad6f72f0db971bd04552c',
contractAddress:
'0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7',
contractFuncName: 'transfer',
contractCallData: [
'0x6b686ebe2cbd70b37b54df1b9889cc3095b55f386110843912efcaed416ff3f',
'0x0de0b6b3a7640000',
],
timestamp: 1655705597,
status: 'Accepted on L1',
eventIds: ['245417_20_0'],
executionStatus: TransactionStatus.SUCCEEDED,
finalityStatus: TransactionStatus.RECEIVED,
failureReason: '',
timestamp: 1655869759,
accountCalls: {
'0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7': [
{
contract:
'0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7',
contractFuncName: 'transfer',
contractCallData: [
'0x6b686ebe2cbd70b37b54df1b9889cc3095b55f386110843912efcaed416ff3f',
'0x0de0b6b3a7640000',
],
},
],
},
maxFee: null,
actualFee: null,
version: 1,
dataVersion: '2',
};

export const FullWidth = () => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
getTxnFailureReason,
getTxnName,
getTxnStatus,
getTxnToFromLabel,
getTxnValues,
} from './types';
import { getHumanReadableAmount, openExplorerTab } from 'utils/utils';
Expand All @@ -32,22 +31,25 @@ interface Props {

export const TransactionListItemView = ({ transaction }: Props) => {
const wallet = useAppSelector((state) => state.wallet);
const tokenAddress = wallet.erc20TokenBalanceSelected.address;
const [currencySymbol, setCurrencySymbol] = useState('N/A');
const [txnValue, setTxnValue] = useState('0');
const [txnUsdValue, setTxnUsdValue] = useState('0.00');

useEffect(() => {
const fetchData = async () => {
// Find the matching token
const foundToken = wallet.erc20TokenBalances.find((token) =>
ethers.BigNumber.from(token.address).eq(
ethers.BigNumber.from(transaction.contractAddress),
ethers.BigNumber.from(tokenAddress),
),
);
if (foundToken) {
const txnValues = getTxnValues(
transaction,
foundToken.decimals,
foundToken.usdPrice,
tokenAddress,
);
setTxnValue(getHumanReadableAmount(foundToken, txnValues.txnValue));
setTxnUsdValue(txnValues.txnUsdValue);
Expand All @@ -58,10 +60,10 @@ export const TransactionListItemView = ({ transaction }: Props) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const txnName = getTxnName(transaction);
const txnName = getTxnName(transaction, tokenAddress);
const txnDate = getTxnDate(transaction);
const txnStatus = getTxnStatus(transaction);
const txnToFromLabel = getTxnToFromLabel(transaction);
const txnToFromLabel = '';
const txnFailureReason = getTxnFailureReason(transaction);
return (
<Wrapper
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { IconProp } from '@fortawesome/fontawesome-svg-core';
import { Transaction, TransactionStatus, VoyagerTransactionType } from 'types';
import { shortenAddress } from 'utils/utils';
import {
Transaction,
TransactionStatus,
StarkscanTransactionType,
} from 'types';
import { ethers } from 'ethers';

export const getIcon = (transactionName: string): IconProp => {
Expand All @@ -17,23 +20,38 @@ export const getIcon = (transactionName: string): IconProp => {
}
};

export const getTxnName = (transaction: Transaction): string => {
if (transaction.txnType.toLowerCase() === VoyagerTransactionType.INVOKE) {
if (transaction.contractFuncName.toLowerCase() === 'transfer') {
return 'Send';
} else if (transaction.contractFuncName.toLowerCase() === 'upgrade') {
return 'Upgrade Account';
}
} else if (
transaction.txnType.toLowerCase() === VoyagerTransactionType.DEPLOY
) {
return 'Deploy';
} else if (
transaction.txnType.toLowerCase() === VoyagerTransactionType.DEPLOY_ACCOUNT
) {
return 'Deploy Account';
export const getTxnName = (
transaction: Transaction,
contractAddress: string,
): string => {
switch (transaction.txnType) {
case StarkscanTransactionType.INVOKE:
if (
transaction.accountCalls &&
transaction.accountCalls[contractAddress]
) {
if (
transaction.accountCalls[contractAddress].some(
(call) => call.contractFuncName === 'transfer',
)
) {
return 'Send';
} else if (
transaction.accountCalls[contractAddress].some(
(call) => call.contractFuncName === 'upgrade',
)
) {
return 'Upgrade Account';
}
}
return 'Contract Interaction';
case StarkscanTransactionType.DEPLOY:
return 'Depoly';
case StarkscanTransactionType.DEPLOY_ACCOUNT:
return 'Deploy Account';
default:
return 'Unknown';
}
return 'Unknown';
};

export const getTxnDate = (transaction: Transaction): string => {
Expand All @@ -50,6 +68,9 @@ export const getTxnDate = (transaction: Transaction): string => {

export const getTxnStatus = (transaction: Transaction): string => {
let statusStr = [];
if (transaction.executionStatus) {
statusStr.push(formatStatus(transaction.executionStatus));
}
if (transaction.finalityStatus === transaction.executionStatus) {
return transaction.finalityStatus
? formatStatus(transaction.finalityStatus)
Expand All @@ -58,9 +79,6 @@ export const getTxnStatus = (transaction: Transaction): string => {
if (transaction.finalityStatus) {
statusStr.push(formatStatus(transaction.finalityStatus));
}
if (transaction.executionStatus) {
statusStr.push(formatStatus(transaction.executionStatus));
}
return statusStr.join(' / ');
};

Expand All @@ -78,29 +96,6 @@ export const formatStatus = (status: string): string => {
.join(' ');
};

export const getTxnToFromLabel = (transaction: Transaction): string => {
const txnName = getTxnName(transaction);
switch (txnName) {
case 'Send':
// TODO : This will not be needed after getTransactions revamp.
if (transaction.contractCallData.length === 3) {
return (
'To ' + shortenAddress(transaction.contractCallData[0].toString())
);
} else {
return (
'To ' + shortenAddress(transaction.contractCallData[4].toString())
);
}
case 'Receive':
return 'From ' + shortenAddress(transaction.senderAddress);
case 'Deploy':
return 'To ' + shortenAddress(transaction.contractAddress);
default:
return '';
}
};

export const getTxnFailureReason = (transaction: Transaction): string => {
return transaction.executionStatus &&
transaction.executionStatus.toLowerCase() ===
Expand All @@ -114,24 +109,25 @@ export const getTxnValues = (
transaction: Transaction,
decimals: number = 18,
toUsdRate: number = 0,
tokenAddress: string,
) => {
let txnValue = '0';
let txnUsdValue = '0';
if (transaction.accountCalls && transaction.accountCalls[tokenAddress]) {
txnValue = ethers.utils.formatUnits(
transaction.accountCalls[tokenAddress]
.filter((call) => call.contractFuncName === 'transfer') // Filter for "transfer" calls
.reduce((acc, call) => {
// Extract the BigInt value from contractCallData
const value = BigInt(
call.contractCallData[call.contractCallData.length - 2].toString(),
);
return acc + value; // Sum the BigInt values
}, BigInt(0)),
decimals,
); // Start with BigInt(0) as the initial value

const txnName = getTxnName(transaction);
switch (txnName) {
case 'Send':
case 'Receive':
txnValue = ethers.utils.formatUnits(
transaction.contractCallData[
transaction.contractCallData.length - 2
].toString(),
decimals,
);
txnUsdValue = (parseFloat(txnValue) * toUsdRate).toFixed(2);
break;
default:
break;
txnUsdValue = (parseFloat(txnValue) * toUsdRate).toFixed(2);
}

return { txnValue, txnUsdValue };
Expand Down
Loading
Loading