Skip to content

Commit 5f9e717

Browse files
authored
Merge pull request #80 from bitsnark/feat/FF-87
8 decimals amount
2 parents 20415aa + 02d138c commit 5f9e717

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

src/components/tabs-switcher/transfer-tab.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Button } from '../ui/button';
77
import { isValidBitcoinAddress } from '@/lib/utils';
88
import { Network, Currency } from './types';
99
import { useChainId } from 'wagmi';
10-
import { Address, parseEther } from 'viem';
10+
import { Address, parseEther, parseUnits } from 'viem';
1111
import { useExchange } from '@/hooks/useExchange';
1212
import { Position, Reservation } from '@/types';
1313
import { useMaxMinBtc } from '@/hooks/queries/useMaxMinBtc';
@@ -137,7 +137,7 @@ export function TransferTab({ onTransactionCreated }: TransferTabProps) {
137137

138138
const handleBridgeFunds = async () => {
139139
const normalizedAmount = fromAmount.replace(',', '.');
140-
const parsedAmount = parseEther(normalizedAmount);
140+
const parsedAmount = parseUnits(normalizedAmount, 8);
141141
let transaction: Position | Reservation | undefined;
142142
if (fromNetwork === 'bitcoin') {
143143
transaction = await reservePosition({

src/hooks/useExchange.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export const useExchange = () => {
8585
try {
8686
setLoading(true);
8787
setError(null);
88-
88+
console.log('openPosition', tokenAmount, exchangeRate, bitcoinAddresses, deadline, owner, chainId);
8989
const contractManager = await ContractManager.getInstance();
9090
const contractAddress = CONTRACTS_ADDRESS[
9191
chainId as keyof typeof CONTRACTS_ADDRESS
@@ -101,18 +101,20 @@ export const useExchange = () => {
101101
tokenAddress
102102
);
103103

104+
console.log('tokenName', tokenName);
104105
const nonce = await contractManager.readContract(
105106
'ERC20BitSnark',
106107
'nonces',
107108
[owner],
108109
tokenAddress
109110
);
111+
console.log('nonce', nonce);
110112
const domain = {
111113
name: tokenName,
112114
version: '1',
113115
verifyingContract: tokenAddress,
114116
};
115-
117+
console.log('domain', domain);
116118
const types = {
117119
Permit: [
118120
{ name: 'owner', type: 'address' },
@@ -122,25 +124,25 @@ export const useExchange = () => {
122124
{ name: 'deadline', type: 'uint256' },
123125
],
124126
};
125-
127+
console.log('types', types);
126128
const message = {
127129
owner,
128130
spender: contractAddress,
129131
value: tokenAmount,
130132
nonce,
131133
deadline,
132134
};
133-
135+
console.log('message', message);
134136
const signature = await contractManager.signTypedData({
135137
domain,
136138
types,
137139
primaryType: 'Permit',
138140
message,
139141
});
140-
142+
console.log('signature', signature);
141143
const { r, s, v } = contractManager.getRSV(signature);
142144
const bytes32 = bech32ToBytes32(bitcoinAddresses);
143-
145+
console.log('bytes32', bytes32);
144146
const { hash, wait } = await contractManager.writeContract(
145147
'AMMExchange',
146148
'openPosition',

src/services/ContractManager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ export class ContractManager {
256256
primaryType: string;
257257
message: T;
258258
}): Promise<`0x${string}`> {
259+
console.log('signTypedData', params, this.walletClient?.account, this.walletClient?.chain?.id);
259260
if (!this.walletClient?.account) {
260261
throw new CMError('Wallet client not initialized');
261262
}

0 commit comments

Comments
 (0)