Skip to content

Commit aac65f4

Browse files
committed
refactor: dynamic transaction gas
1 parent 90bf650 commit aac65f4

File tree

3 files changed

+71
-75
lines changed

3 files changed

+71
-75
lines changed

wallets/rn_cli_wallet/src/modals/SessionSendTransactionModal.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {useSnapshot} from 'valtio';
22
import {useCallback, useEffect, useMemo, useState} from 'react';
3-
import {View, StyleSheet, Image, Text} from 'react-native';
3+
import {View, StyleSheet, Image, Text, Alert} from 'react-native';
44
import {SignClientTypes} from '@walletconnect/types';
55
import {ChainAbstractionTypes} from '@reown/walletkit';
66
import {
@@ -186,10 +186,12 @@ export default function SessionSendTransactionModal() {
186186
});
187187
} catch (e) {
188188
console.log((e as Error).message, 'error');
189-
return;
190-
} finally {
189+
Alert.alert((e as Error).message);
191190
setApproveLoading(false);
191+
return;
192192
}
193+
194+
setApproveLoading(false);
193195
ModalStore.close();
194196
}
195197
}, [

wallets/rn_cli_wallet/src/utils/EIP155RequestHandlerUtil.ts

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -61,49 +61,43 @@ export async function approveEIP155Request(
6161
}
6262

6363
case EIP155_SIGNING_METHODS.ETH_SEND_TRANSACTION:
64-
try {
65-
let hash = '';
66-
if (additionalTransactions.length > 0) {
67-
console.log(
68-
'starting processing transactions: ',
69-
additionalTransactions.length,
70-
);
71-
for (const transaction of additionalTransactions) {
72-
const chain = transaction.chainId
73-
? parseChainId(transaction.chainId)
74-
: parseChainId(chainId);
75-
const chainData = PresetsUtil.getChainData(chain);
76-
const provider = new providers.JsonRpcProvider(chainData.rpcUrl);
77-
const connectedWallet = wallet.connect(provider);
78-
console.log('sending transaction...', chain, transaction);
79-
// await new Promise(resolve => setTimeout(resolve, 10_000));
80-
delete transaction.chainId;
81-
const result = await connectedWallet.sendTransaction({
82-
...transaction,
83-
nonce: await provider.getTransactionCount(transaction.from),
84-
});
85-
console.log('transaction sent - hash:', result.hash);
86-
console.log('waiting for transaction to be mined...');
87-
const receipt = await waitForTransaction(result.hash, provider);
88-
console.log('transaction mined:', receipt);
89-
hash = result.hash;
90-
}
91-
} else {
92-
const chainData = PresetsUtil.getChainData(parseChainId(chainId));
64+
let hash = '';
65+
if (additionalTransactions.length > 0) {
66+
console.log(
67+
'starting processing transactions: ',
68+
additionalTransactions.length,
69+
);
70+
for (const transaction of additionalTransactions) {
71+
const chain = transaction.chainId
72+
? parseChainId(transaction.chainId)
73+
: parseChainId(chainId);
74+
const chainData = PresetsUtil.getChainData(chain);
9375
const provider = new providers.JsonRpcProvider(chainData.rpcUrl);
94-
const sendTransaction = request.params[0];
9576
const connectedWallet = wallet.connect(provider);
96-
const result = await connectedWallet.sendTransaction(sendTransaction);
77+
console.log('sending transaction...', chain, transaction);
78+
// await new Promise(resolve => setTimeout(resolve, 10_000));
79+
delete transaction.chainId;
80+
const result = await connectedWallet.sendTransaction({
81+
...transaction,
82+
nonce: await provider.getTransactionCount(transaction.from),
83+
});
84+
console.log('transaction sent - hash:', result.hash);
85+
console.log('waiting for transaction to be mined...');
86+
const receipt = await waitForTransaction(result.hash, provider);
87+
console.log('transaction mined:', receipt);
9788
hash = result.hash;
9889
}
99-
100-
return formatJsonRpcResult(id, hash);
101-
} catch (error: any) {
102-
console.error(error);
103-
console.log(error.message);
104-
return formatJsonRpcError(id, error.message);
90+
} else {
91+
const chainData = PresetsUtil.getChainData(parseChainId(chainId));
92+
const provider = new providers.JsonRpcProvider(chainData.rpcUrl);
93+
const sendTransaction = request.params[0];
94+
const connectedWallet = wallet.connect(provider);
95+
const result = await connectedWallet.sendTransaction(sendTransaction);
96+
hash = result.hash;
10597
}
10698

99+
return formatJsonRpcResult(id, hash);
100+
107101
case EIP155_SIGNING_METHODS.ETH_SIGN_TRANSACTION:
108102
try {
109103
const signTransaction = request.params[0];

wallets/rn_cli_wallet/src/utils/EIP155WalletUtil.ts

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -136,41 +136,41 @@ export async function calculateEip155Gas(transaction: any, chainId: string) {
136136
}
137137

138138
const fetchGasPrice = async (chainId: string) => {
139-
// const result = await fetch(
140-
// `https://tokentool.bitbond.com/api/gas-price-20240116?chain_id=${parseChainId(
141-
// chainId,
142-
// )}&timestamp=${Date.now()}`,
143-
// );
144-
// const data = await result.json();
145-
// console.log('fetchGasPrice:', data);
146-
// return data?.data;
147-
148-
const result = {
149-
data: {
150-
fast: {
151-
estimated_seconds: 0,
152-
front_tx_count: 0,
153-
level: 'fast',
154-
price: 11006500,
155-
priority_price: 1200000,
156-
},
157-
normal: {
158-
estimated_seconds: 0,
159-
front_tx_count: 0,
160-
level: 'normal',
161-
price: 1200800,
162-
priority_price: 1100000,
163-
},
164-
slow: {
165-
estimated_seconds: 0,
166-
front_tx_count: 0,
167-
level: 'slow',
168-
price: 1000600,
169-
priority_price: 1000000,
170-
},
171-
},
172-
success: true,
173-
};
139+
const result = await fetch(
140+
`https://tokentool.bitbond.com/api/gas-price-20240116?chain_id=${parseChainId(
141+
chainId,
142+
)}&timestamp=${Date.now()}`,
143+
);
144+
const data = await result.json();
145+
console.log('fetchGasPrice:', data);
146+
return data?.data;
147+
148+
// const result = {
149+
// data: {
150+
// fast: {
151+
// estimated_seconds: 0,
152+
// front_tx_count: 0,
153+
// level: 'fast',
154+
// price: 11006500,
155+
// priority_price: 1200000,
156+
// },
157+
// normal: {
158+
// estimated_seconds: 0,
159+
// front_tx_count: 0,
160+
// level: 'normal',
161+
// price: 1200800,
162+
// priority_price: 1100000,
163+
// },
164+
// slow: {
165+
// estimated_seconds: 0,
166+
// front_tx_count: 0,
167+
// level: 'slow',
168+
// price: 1000600,
169+
// priority_price: 1000000,
170+
// },
171+
// },
172+
// success: true,
173+
// };
174174
return result.data;
175175
};
176176

0 commit comments

Comments
 (0)