Skip to content

Commit e607ef2

Browse files
authored
feat: use shared configs in headers as well (#86)
2 parents b4f53f7 + 1a85c59 commit e607ef2

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ app.post("/", async (req, res, next) => {
7373

7474
// Get Oval header configs if present.
7575
const { ovalAddresses: headerOvalAddresses, errorMessage } = getOvalHeaderConfigs(
76-
req.headers[OVAL_ADDRESSES_HEADER],
77-
ovalConfigs,
76+
req.headers[OVAL_ADDRESSES_HEADER]
7877
);
7978
if (errorMessage) {
8079
await handleUnsupportedRequest(req, res, "Error parsing Oval header configs: " + errorMessage);
@@ -128,7 +127,7 @@ app.post("/", async (req, res, next) => {
128127
{
129128
bodyIdx: 0,
130129
// Next line is dependent on all Oval addresses having the same refund address
131-
percent: ovalConfigs[headerOvalAddresses[0]].refundPercent,
130+
percent: getOvalRefundConfig(headerOvalAddresses[0]).refundPercent,
132131
},
133132
];
134133

@@ -157,7 +156,7 @@ app.post("/", async (req, res, next) => {
157156
// costs exceed refund value.
158157
const adjustedRefundPercent = adjustRefundPercent(
159158
unlock.simulationResponse.coinbaseDiff,
160-
ovalConfigs[unlock.ovalAddress].refundPercent,
159+
getOvalRefundConfig(unlock.ovalAddress).refundPercent,
161160
);
162161
if (adjustedRefundPercent <= 0) {
163162
Logger.debug(req.transactionId, `Insufficient builder payment ${unlock.simulationResponse.coinbaseDiff}`);

src/lib/helpers.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,7 @@ export const getOvalRefundConfig = (ovalAddress: string): RefundConfig => {
299299

300300
// Get OvalAddressConfigList from the header string or throw an error if the header is invalid.
301301
export const getOvalHeaderConfigs = (
302-
header: string | string[] | undefined,
303-
ovalConfigs: OvalConfigs,
302+
header: string | string[] | undefined
304303
): { errorMessage?: string; ovalAddresses: OvalAddressConfigList | undefined } => {
305304
if (!header) return { ovalAddresses: undefined };
306305
if (typeof header !== "string") return { ovalAddresses: undefined };

0 commit comments

Comments
 (0)