Skip to content

Commit

Permalink
feat: use shared configs in headers as well
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Maldonado <pablo@umaproject.org>
  • Loading branch information
md0x committed Aug 8, 2024
1 parent b4f53f7 commit 1a85c59
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ app.post("/", async (req, res, next) => {

// Get Oval header configs if present.
const { ovalAddresses: headerOvalAddresses, errorMessage } = getOvalHeaderConfigs(
req.headers[OVAL_ADDRESSES_HEADER],
ovalConfigs,
req.headers[OVAL_ADDRESSES_HEADER]
);
if (errorMessage) {
await handleUnsupportedRequest(req, res, "Error parsing Oval header configs: " + errorMessage);
Expand Down Expand Up @@ -128,7 +127,7 @@ app.post("/", async (req, res, next) => {
{
bodyIdx: 0,
// Next line is dependent on all Oval addresses having the same refund address
percent: ovalConfigs[headerOvalAddresses[0]].refundPercent,
percent: getOvalRefundConfig(headerOvalAddresses[0]).refundPercent,
},
];

Expand Down Expand Up @@ -157,7 +156,7 @@ app.post("/", async (req, res, next) => {
// costs exceed refund value.
const adjustedRefundPercent = adjustRefundPercent(
unlock.simulationResponse.coinbaseDiff,
ovalConfigs[unlock.ovalAddress].refundPercent,
getOvalRefundConfig(unlock.ovalAddress).refundPercent,
);
if (adjustedRefundPercent <= 0) {
Logger.debug(req.transactionId, `Insufficient builder payment ${unlock.simulationResponse.coinbaseDiff}`);
Expand Down
3 changes: 1 addition & 2 deletions src/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,7 @@ export const getOvalRefundConfig = (ovalAddress: string): RefundConfig => {

// Get OvalAddressConfigList from the header string or throw an error if the header is invalid.
export const getOvalHeaderConfigs = (
header: string | string[] | undefined,
ovalConfigs: OvalConfigs,
header: string | string[] | undefined
): { errorMessage?: string; ovalAddresses: OvalAddressConfigList | undefined } => {
if (!header) return { ovalAddresses: undefined };
if (typeof header !== "string") return { ovalAddresses: undefined };
Expand Down

0 comments on commit 1a85c59

Please sign in to comment.