Skip to content

Commit

Permalink
Merge pull request #390 from EdgeApp/sam/max-fee-fix
Browse files Browse the repository at this point in the history
Add optional fallback generic parameter to asFeeInfo cleaner
  • Loading branch information
samholmes authored Oct 28, 2023
2 parents 4e6760e + d3c82b0 commit 91beb37
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- fixed: Bug with new `maximumFeeRate` entry in `FeeInfo` not applying due to disk/info-server overwriting the field.

## 2.4.0 (2023-10-23)

- changed: Re-enabled maximum fee rate checks from AltcoinJS.
Expand Down
4 changes: 2 additions & 2 deletions src/common/fees/makeFees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const makeFees = async (config: MakeFeesConfig): Promise<Fees> => {
const edgeFees = await fetchFees({
...common,
uri: `${INFO_SERVER_URI}/v1/networkFees/${currencyInfo.pluginId}`,
cleaner: asMaybe(asFeeInfo, null)
cleaner: asMaybe(asFeeInfo(feeInfo), null)
})
Object.assign(feeInfo, edgeFees)
await updateVendorFees()
Expand Down Expand Up @@ -122,7 +122,7 @@ const fetchCachedFees = async (
fallback: FeeInfo
): Promise<FeeInfo> => {
const data = await memlet.getJson(FEES_PATH).catch(() => undefined)
const feeSettings = asMaybe(asFeeInfo, fallback)(data)
const feeSettings = asMaybe(asFeeInfo(fallback), fallback)(data)
return feeSettings
}

Expand Down
37 changes: 22 additions & 15 deletions src/common/plugin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,28 @@ export type FeeInfo = FeeRates & {
standardFeeHighAmount: string
maximumFeeRate?: string
}
export const asFeeInfo = asObject<FeeInfo>({
...asFeeRates.shape,

lowFeeFudgeFactor: asMaybe(asString),
standardFeeLowFudgeFactor: asMaybe(asString),
standardFeeHighFudgeFactor: asMaybe(asString),
highFeeFudgeFactor: asMaybe(asString),

// The amount of satoshis which will be charged the standardFeeLow
standardFeeLowAmount: asString,
// The amount of satoshis which will be charged the standardFeeHigh
standardFeeHighAmount: asString,
// A safe-guard for any potential software bugs:
maximumFeeRate: asOptional(asString)
})
export const asFeeInfo = (fallback?: FeeInfo): Cleaner<FeeInfo> =>
asObject<FeeInfo>({
...asFeeRates.shape,

lowFeeFudgeFactor: asMaybe(asString, fallback?.lowFeeFudgeFactor),
standardFeeLowFudgeFactor: asMaybe(
asString,
fallback?.standardFeeLowFudgeFactor
),
standardFeeHighFudgeFactor: asMaybe(
asString,
fallback?.standardFeeHighFudgeFactor
),
highFeeFudgeFactor: asMaybe(asString, fallback?.highFeeFudgeFactor),

// The amount of satoshis which will be charged the standardFeeLow
standardFeeLowAmount: asString,
// The amount of satoshis which will be charged the standardFeeHigh
standardFeeHighAmount: asString,
// A safe-guard for any potential software bugs:
maximumFeeRate: asOptional(asString, fallback?.maximumFeeRate)
}).withRest

export interface EngineConfig {
walletInfo: EdgeWalletInfo
Expand Down

0 comments on commit 91beb37

Please sign in to comment.