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

added token decimals to token related components #102

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## [0.7.5] - 2024-02-21

### Added Changes
- Added missing `tokenDecimals` param to `<EtherspotTokenTransferTransaction />` and `<EtherspotApprovalTransaction />` components

## [0.7.4] - 2024-02-20

### Added Changes
Expand Down
11 changes: 9 additions & 2 deletions __tests__/components/EtherspotApprovalTransaction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ describe('EtherspotApprovalTransaction', () => {
<EtherspotApprovalTransaction
tokenAddress={'0xe3818504c1b32bf1557b16c238b2e01fd3149c17'}
receiverAddress={'0x7F30B1960D5556929B03a0339814fE903c55a347'}
value={ethers.utils.parseEther('123')}
value={ethers.utils.parseUnits('123', 10)}
/>
<EtherspotApprovalTransaction
tokenAddress={'0xe3818504c1b32bf1557b16c238b2e01fd3149c17'}
receiverAddress={'0x7F30B1960D5556929B03a0339814fE903c55a347'}
value={'123'}
tokenDecimals={10}
/>
</EtherspotBatch>
</EtherspotBatches>
Expand All @@ -80,8 +86,9 @@ describe('EtherspotApprovalTransaction', () => {
const { result: { current } } = renderHook(() => useEtherspotTransactions(), { wrapper });

expect(current.batches[0].batches[0].transactions[0].to).toBe('0xe3818504c1b32bf1557b16c238b2e01fd3149c17');
expect(current.batches[0].batches[0].transactions[0].data).toBe('0x095ea7b30000000000000000000000007f30b1960d5556929b03a0339814fe903c55a347000000000000000000000000000000000000000000000006aaf7c8516d0c0000');
expect(current.batches[0].batches[0].transactions[0].data).toBe('0x095ea7b30000000000000000000000007f30b1960d5556929b03a0339814fe903c55a3470000000000000000000000000000000000000000000000000000011e61b68c00');
expect(current.batches[0].batches[0].transactions[0].value).toBe(undefined);
expect(current.batches[0].batches[0].transactions[1].data).toBe('0x095ea7b30000000000000000000000007f30b1960d5556929b03a0339814fe903c55a3470000000000000000000000000000000000000000000000000000011e61b68c00');
});

})
11 changes: 9 additions & 2 deletions __tests__/components/EtherspotTokenTransferTransaction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ describe('EtherspotTokenTransferTransaction', () => {
<EtherspotTokenTransferTransaction
tokenAddress={'0xe3818504c1b32bf1557b16c238b2e01fd3149c17'}
receiverAddress={'0x7F30B1960D5556929B03a0339814fE903c55a347'}
value={ethers.utils.parseEther('123')}
value={ethers.utils.parseUnits('123', 10)}
/>
<EtherspotTokenTransferTransaction
tokenAddress={'0xe3818504c1b32bf1557b16c238b2e01fd3149c17'}
receiverAddress={'0x7F30B1960D5556929B03a0339814fE903c55a347'}
value={'123'}
tokenDecimals={10}
/>
</EtherspotBatch>
</EtherspotBatches>
Expand All @@ -88,7 +94,8 @@ describe('EtherspotTokenTransferTransaction', () => {
await waitFor(() => expect(result.current.batches[0].batches[0].transactions[0]).not.toBe(undefined));

expect(result.current.batches[0].batches[0].transactions[0].to).toBe('0xe3818504c1b32bf1557b16c238b2e01fd3149c17');
expect(result.current.batches[0].batches[0].transactions[0].data).toBe('0xa9059cbb0000000000000000000000007f30b1960d5556929b03a0339814fe903c55a347000000000000000000000000000000000000000000000006aaf7c8516d0c0000');
expect(result.current.batches[0].batches[0].transactions[0].data).toBe('0xa9059cbb0000000000000000000000007f30b1960d5556929b03a0339814fe903c55a3470000000000000000000000000000000000000000000000000000011e61b68c00');
expect(result.current.batches[0].batches[0].transactions[0].value).toBe(undefined);
expect(result.current.batches[0].batches[0].transactions[1].data).toBe('0xa9059cbb0000000000000000000000007f30b1960d5556929b03a0339814fe903c55a3470000000000000000000000000000000000000000000000000000011e61b68c00');
});
})
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@etherspot/transaction-kit",
"description": "React Etherspot Transaction Kit",
"version": "0.7.4",
"version": "0.7.5",
"main": "dist/cjs/index.js",
"scripts": {
"rollup:build": "NODE_OPTIONS=--max-old-space-size=8192 rollup -c",
Expand Down
7 changes: 4 additions & 3 deletions src/components/EtherspotApprovalTransaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ const EtherspotApprovalTransaction = ({
value,
tokenAddress,
receiverAddress,
id: transactionId
}: EtherspotApprovalTransactionProps) => {
id: transactionId,
tokenDecimals = 18,
}: EtherspotApprovalTransactionProps): React.ReactNode => {
const context = useContext(EtherspotBatchContext);
const componentId = useId();

Expand All @@ -40,7 +41,7 @@ const EtherspotApprovalTransaction = ({
let valueBN;
try {
valueBN = typeof value === 'string' && !ethers.BigNumber.isBigNumber(value)
? ethers.utils.parseEther(value)
? ethers.utils.parseUnits(value, tokenDecimals)
: value;
} catch (e) {
if (e instanceof Error && e?.message) {
Expand Down
7 changes: 4 additions & 3 deletions src/components/EtherspotTokenTransferTransaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ const EtherspotTokenTransferTransaction = ({
value,
tokenAddress,
receiverAddress,
id: transactionId
}: EtherspotTokenTransferTransactionProps): JSX.Element => {
id: transactionId,
tokenDecimals = 18,
}: EtherspotTokenTransferTransactionProps): React.ReactNode => {
const context = useContext(EtherspotBatchContext);
const componentId = useId();
const senderAddress = useWalletAddress('etherspot-prime', context?.chainId);
Expand All @@ -42,7 +43,7 @@ const EtherspotTokenTransferTransaction = ({
let valueBN;
try {
valueBN = typeof value === 'string' && !ethers.BigNumber.isBigNumber(value)
? ethers.utils.parseEther(value)
? ethers.utils.parseUnits(value, tokenDecimals)
: value;
} catch (e) {
if (e instanceof Error && e?.message) {
Expand Down
2 changes: 2 additions & 0 deletions src/types/EtherspotTransactionKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export interface IEtherspotTokenTransferTransaction {
value: BigNumberish;
tokenAddress: string;
receiverAddress: string;
tokenDecimals?: number;
}

export interface ISmartWalletAddress {
Expand All @@ -79,6 +80,7 @@ export interface IEtherspotApprovalTransaction {
value: BigNumberish;
tokenAddress: string;
receiverAddress: string;
tokenDecimals?: number;
}

export interface ISameChainSwapOffers {
Expand Down
Loading