Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.

Commit 6a17184

Browse files
committed
feat: use user selected gas speed for price calculations
1 parent dd1fc7d commit 6a17184

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

ts/hooks/use_allowance.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ export const useAllowance = (): UseAllowanceHookResult => {
4040
setIsStarted(true);
4141
const ownerAddress = (providerState.account as AccountReady).address;
4242

43-
// const localStorageSpeed = localStorage.getItem('gas-speed');
44-
const gasInfo = await backendClient.getGasInfoAsync();
43+
const localStorageSpeed = localStorage.getItem('gas-speed');
44+
const gasInfo = await backendClient.getGasInfoAsync(localStorageSpeed);
4545

4646
const contractAddresses = getContractAddressesForChainOrThrow(networkId);
4747
const erc20ProxyAddress = contractAddresses.erc20Proxy;

ts/hooks/use_stake.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ export const useStake = (networkId: ChainId, providerState: ProviderState): UseS
118118
async (data: string[]) => {
119119
setLoadingState(TransactionLoadingState.WaitingForSignature);
120120

121-
// const localStorageSpeed = localStorage.getItem('gas-speed');
122-
const gasInfo = await backendClient.getGasInfoAsync();
121+
const localStorageSpeed = localStorage.getItem('gas-speed');
122+
const gasInfo = await backendClient.getGasInfoAsync(localStorageSpeed);
123123
const txPromise = stakingProxyContract.batchExecute(data).awaitTransactionSuccessAsync({
124124
from: ownerAddress,
125125
maxFeePerGas: gasInfo.maxFeePerGas,
@@ -251,7 +251,8 @@ export const useStake = (networkId: ChainId, providerState: ProviderState): UseS
251251

252252
setLoadingState(TransactionLoadingState.WaitingForSignature);
253253

254-
const gasInfo = await backendClient.getGasInfoAsync();
254+
const localStorageSpeed = localStorage.getItem('gas-speed');
255+
const gasInfo = await backendClient.getGasInfoAsync(localStorageSpeed);
255256

256257
const txPromise = stakingContract.unstake(zrxAmountBaseUnits).awaitTransactionSuccessAsync({
257258
from: ownerAddress,

ts/pages/governance/vote_form.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ class VoteFormComponent extends React.Component<Props> {
274274

275275
const { votePreference } = this.state;
276276

277-
// const localStorageSpeed = localStorage.getItem('gas-speed');
278-
const gasInfo = await backendClient.getGasInfoAsync();
277+
const localStorageSpeed = localStorage.getItem('gas-speed');
278+
const gasInfo = await backendClient.getGasInfoAsync(localStorageSpeed);
279279

280280
const txPromise = contract
281281
.castVote(

ts/utils/backend_client.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@ export const backendClient = {
205205
return data;
206206
},
207207

208-
async getGasInfoAsync(speed?: GasSpeedSelectors): Promise<GasInfo> {
208+
async getGasInfoAsync(speed?: string): Promise<GasInfo> {
209209
const gasApiPath = 'v2/source/block_native';
210210
const gasInfoReq: Promise<GasApiSingleSourceResponse> = fetchUtils.requestAsync(ZEROEX_GAS_API, gasApiPath);
211-
const speedInput: GasSpeedSelectors = speed || 'standard';
211+
const speedInput = speed || 'standard';
212212

213213
const gasWaitTimesReq = fetchUtils.requestAsync(utils.getBackendBaseUrl(), ETH_GAS_STATION_ENDPOINT);
214214

@@ -220,7 +220,12 @@ export const backendClient = {
220220
const waitTime = speedToWaitTimeMap[speedInput];
221221
const estimatedTimeMs = (gasWaitTimes as any)[waitTime] * 60 * 1000; // Minutes to MS
222222

223-
return { ...gasInfo.result[speedInput], estimatedTimeMs };
223+
// Try to use user selected value, fall back to standard if no match
224+
const gasPriceInfo = gasInfo.result[speedInput as GasSpeedSelectors]
225+
? gasInfo.result[speedInput as GasSpeedSelectors]
226+
: gasInfo.result.standard;
227+
228+
return { ...gasPriceInfo, estimatedTimeMs };
224229
},
225230

226231
async getGasInfoSelectionAsync(): Promise<GasInfoSelection> {

0 commit comments

Comments
 (0)