Skip to content

Commit

Permalink
Add explaining comment, improve hex parser in SwapIFrameApi
Browse files Browse the repository at this point in the history
  • Loading branch information
sisou committed Oct 13, 2023
1 parent 06c80df commit 151e112
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/request/swap-iframe/SwapIFrameApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ class SwapIFrameApi extends BitcoinRequestParserMixin(RequestParser) { // eslint
value: 0,
}));

// The htlcData given by Fastspot and forwarded here is always for the open() function, not for
// openWithApproval(). The approval, if requested, is added below, from the stored request where
// the user gave their authorization.
if (description.name !== 'open') {
throw new Errors.InvalidRequestError('Invalid method in HTLC data');
}
Expand All @@ -261,7 +264,9 @@ class SwapIFrameApi extends BitcoinRequestParserMixin(RequestParser) { // eslint
if (request.redeem.type === 'USDC' && storedRequest.redeem.type === 'USDC') {
redeem = {
type: 'USDC',
htlcId: `0x${Nimiq.BufferUtils.toHex(Nimiq.BufferUtils.fromAny(request.redeem.htlcId.substring(2)))}`,
htlcId: `0x${Nimiq.BufferUtils.toHex(Nimiq.BufferUtils.fromAny(
request.redeem.htlcId.replace(/^0x/i, ''),
))}`,
htlcDetails: {
hash: Nimiq.BufferUtils.toHex(Nimiq.BufferUtils.fromAny(request.redeem.hash)),
timeoutTimestamp: this.parsePositiveInteger(request.redeem.timeout, false, 'redeem.timeout'),
Expand Down Expand Up @@ -701,7 +706,7 @@ class SwapIFrameApi extends BitcoinRequestParserMixin(RequestParser) { // eslint
/* bytes32 id */ parsedRequest.redeem.htlcId,
/* address target */ storedRequest.redeem.description.args.target,
...(storedRequest.redeem.description.name === 'redeem' ? [
/* uint256 approval */ storedRequest.redeem.description.args.secret,
/* uint256 secret */ storedRequest.redeem.description.args.secret,
] : []),
/* uint256 fee */ storedRequest.redeem.description.args.fee,
],
Expand Down

0 comments on commit 151e112

Please sign in to comment.