Skip to content

Commit

Permalink
Merge pull request #4 from upbond/WALLET-539
Browse files Browse the repository at this point in the history
WALLET-539| fix: lint and prebuild
  • Loading branch information
ardiyu07 authored Jul 24, 2023
2 parents 3a8fff0 + 63aea45 commit 716cab6
Show file tree
Hide file tree
Showing 6 changed files with 2,319 additions and 2,317 deletions.
8 changes: 3 additions & 5 deletions src/services/gas-estimation/eip1559.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { BG_ZERO, DEFAULT_BLOCK_DURATION, PERCENT_MULTIPLIER } from '@/constants

import { DEFAULT_PRIORITY_FEE, PRIORITY_FEE_INCREASE_BOUNDARY, FEE_HISTORY_BLOCKS, FEE_HISTORY_PERCENTILE } from './constants'

import * as Sentry from "@sentry/browser"
import * as Sentry from '@sentry/browser'

// !!! MAKE SENSE ALL CALCULATIONS IN GWEI !!!
export class Eip1559GasPriceOracle implements EstimateOracle {
Expand Down Expand Up @@ -42,7 +42,6 @@ export class Eip1559GasPriceOracle implements EstimateOracle {
}

public async estimateFees(fallbackGasPrices?: EstimatedGasPrice): Promise<EstimatedGasPrice> {

try {
const cacheKey = this.FEES_KEY(this.configuration.chainId)
const cachedFees = await this.cache.get(cacheKey)
Expand Down Expand Up @@ -78,7 +77,7 @@ export class Eip1559GasPriceOracle implements EstimateOracle {
return fees
} catch (err) {
if (isSentryReady()) {
Sentry.captureException(err); // Check if Sentry is ready before capturing the exception.
Sentry.captureException(err) // Check if Sentry is ready before capturing the exception.
}
if (fallbackGasPrices) {
return fallbackGasPrices
Expand Down Expand Up @@ -127,7 +126,6 @@ export class Eip1559GasPriceOracle implements EstimateOracle {
}

private async getPriorityFromChain(feeHistory?: FeeHistory) {

try {
const { data } = await this.fetcher.makeRpcCall<{ result: string }>({
method: 'eth_maxPriorityFeePerGas',
Expand All @@ -137,7 +135,7 @@ export class Eip1559GasPriceOracle implements EstimateOracle {
return fromWeiToGwei(data.result)
} catch (err) {
if (isSentryReady()) {
Sentry.captureException(err); // Check if Sentry is ready before capturing the exception.
Sentry.captureException(err) // Check if Sentry is ready before capturing the exception.
}
return this.calculatePriorityFeeEstimate(feeHistory)
}
Expand Down
15 changes: 6 additions & 9 deletions src/services/gas-price-oracle/gas-price-oracle-init-sentry.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
// gasPriceOracleInit.ts

import * as Sentry from "@sentry/browser";
import * as Sentry from '@sentry/browser'

let isSentryInitialized = false;
let isSentryInitialized = false

export function initializeSentry(dsn: string | undefined) {
Sentry.init({
dsn,
integrations: [
new Sentry.BrowserTracing(),
new Sentry.Replay(),
],
integrations: [new Sentry.BrowserTracing(), new Sentry.Replay()],
tracesSampleRate: 1.0,
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
});
})

// after sentry has initialized
isSentryInitialized = true;
isSentryInitialized = true
}

export function isSentryReady(): boolean {
return isSentryInitialized;
return isSentryInitialized
}
6 changes: 3 additions & 3 deletions src/services/gas-price-oracle/gas-price-oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
isSentryReady,
} from '@/services'

import * as Sentry from "@sentry/browser"
import * as Sentry from '@sentry/browser'

export class GasPriceOracle implements OracleProvider {
public eip1559: EstimateOracle
Expand Down Expand Up @@ -60,7 +60,7 @@ export class GasPriceOracle implements OracleProvider {
return await this.eip1559.estimateFees(fallbackGasPrices?.estimated)
} catch (err) {
if (isSentryReady()) {
Sentry.captureException(err); // Check if Sentry is ready before capturing the exception.
Sentry.captureException(err) // Check if Sentry is ready before capturing the exception.
}
return await this.legacy.gasPrices(fallbackGasPrices?.gasPrices, shouldGetMedian)
}
Expand All @@ -83,7 +83,7 @@ export class GasPriceOracle implements OracleProvider {
}
} catch (err) {
if (isSentryReady()) {
Sentry.captureException(err); // Check if Sentry is ready before capturing the exception.
Sentry.captureException(err) // Check if Sentry is ready before capturing the exception.
}
const legacyGasPrice = await this.legacy.gasPrices(fallbackGasPrices?.gasPrices, shouldGetMedian)

Expand Down
2 changes: 1 addition & 1 deletion src/services/gas-price-oracle/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './gas-price-oracle'
export * from "./gas-price-oracle-init-sentry"
export * from './gas-price-oracle-init-sentry'
export * from './types'
17 changes: 7 additions & 10 deletions src/services/legacy-gas-price/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { GWEI, DEFAULT_TIMEOUT, GWEI_PRECISION, DEFAULT_BLOCK_DURATION } from '@

import { MULTIPLIERS, DEFAULT_GAS_PRICE } from './constants'

import * as Sentry from "@sentry/browser"
import * as Sentry from '@sentry/browser'

export class LegacyGasPriceOracle implements LegacyOracle {
static getMedianGasPrice(gasPrices: GasPrice[]): GasPrice {
Expand Down Expand Up @@ -145,7 +145,6 @@ export class LegacyGasPriceOracle implements LegacyOracle {
}

public async fetchGasPricesOnChain(): Promise<number> {

for (const oracle of Object.values(this.onChainOracles)) {
const { name, callData, contract, denominator, rpc } = oracle

Expand All @@ -166,15 +165,14 @@ export class LegacyGasPriceOracle implements LegacyOracle {
throw new Error(`Fetch gasPrice from ${name} oracle failed. Trying another one...`)
} catch (e) {
if (isSentryReady()) {
Sentry.captureException(e); // Check if Sentry is ready before capturing the exception.
Sentry.captureException(e) // Check if Sentry is ready before capturing the exception.
}
}
}
throw new Error('All oracles are down. Probably a network error.')
}

public async fetchGasPriceFromRpc(): Promise<number> {

try {
const { status, data } = await this.fetcher.makeRpcCall<{ result: string | number }>({
params: [],
Expand All @@ -191,7 +189,7 @@ export class LegacyGasPriceOracle implements LegacyOracle {
throw new Error(`Fetch gasPrice from default RPC failed..`)
} catch (e) {
if (isSentryReady()) {
Sentry.captureException(e); // Check if Sentry is ready before capturing the exception.
Sentry.captureException(e) // Check if Sentry is ready before capturing the exception.
}
throw new Error('Default RPC is down. Probably a network error.')
}
Expand All @@ -207,7 +205,7 @@ export class LegacyGasPriceOracle implements LegacyOracle {
return await this.askOracle(oracle)
} catch (e) {
if (isSentryReady()) {
Sentry.captureException(e); // Check if Sentry is ready before capturing the exception.
Sentry.captureException(e) // Check if Sentry is ready before capturing the exception.
}
continue
}
Expand Down Expand Up @@ -240,7 +238,6 @@ export class LegacyGasPriceOracle implements LegacyOracle {
}

public async gasPrices(fallbackGasPrices?: GasPrice, shouldGetMedian = true): Promise<GasPrice> {

if (!this.lastGasPrice) {
this.lastGasPrice = fallbackGasPrices || this.configuration.fallbackGasPrices
}
Expand All @@ -260,7 +257,7 @@ export class LegacyGasPriceOracle implements LegacyOracle {
return this.lastGasPrice
} catch (e) {
if (isSentryReady()) {
Sentry.captureException(e); // Check if Sentry is ready before capturing the exception.
Sentry.captureException(e) // Check if Sentry is ready before capturing the exception.
}
}
}
Expand All @@ -276,7 +273,7 @@ export class LegacyGasPriceOracle implements LegacyOracle {
return this.lastGasPrice
} catch (e) {
if (isSentryReady()) {
Sentry.captureException(e); // Check if Sentry is ready before capturing the exception.
Sentry.captureException(e) // Check if Sentry is ready before capturing the exception.
}
}
}
Expand All @@ -291,7 +288,7 @@ export class LegacyGasPriceOracle implements LegacyOracle {
return this.lastGasPrice
} catch (e) {
if (isSentryReady()) {
Sentry.captureException(e); // Check if Sentry is ready before capturing the exception.
Sentry.captureException(e) // Check if Sentry is ready before capturing the exception.
}
}
return LegacyGasPriceOracle.normalize(this.lastGasPrice)
Expand Down
Loading

0 comments on commit 716cab6

Please sign in to comment.