Skip to content

Commit 48d3640

Browse files
authored
Merge pull request #1023 from input-output-hk/fix/get-collateral-sender-arg
feat(wallet): forward MessageSender to GetCollateralCallback
2 parents ba078b3 + da4ab32 commit 48d3640

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

packages/wallet/src/cip30.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export type SubmitTxCallbackParams = {
5959

6060
// Optional callback
6161
export type GetCollateralCallbackParams = {
62+
sender: MessageSender;
6263
type: Cip30ConfirmationCallbackType.GetCollateral;
6364
data: {
6465
amount: Cardano.Lovelace;
@@ -208,13 +209,15 @@ const getFilterAmount = (amount: Cbor): bigint => {
208209
/**
209210
* getCollateralCallback
210211
*
212+
* @param sender The sender of the request
211213
* @param amount ADA collateral required in lovelaces
212214
* @param availableUtxos available UTxOs
213215
* @param callback Callback to execute to attempt setting new collateral
214216
* @param logger The logger instance
215217
* @returns Promise<Cbor[]> or null
216218
*/
217219
const getCollateralCallback = async (
220+
sender: MessageSender,
218221
amount: Cardano.Lovelace,
219222
availableUtxos: Cardano.Utxo[],
220223
callback: GetCollateralCallback,
@@ -230,6 +233,7 @@ const getCollateralCallback = async (
230233
amount,
231234
utxos: availableUtxosWithoutAssets
232235
},
236+
sender,
233237
type: Cip30ConfirmationCallbackType.GetCollateral
234238
});
235239
return newCollateral.map((core) => Serialization.TransactionUnspentOutput.fromCore(core).toCbor());
@@ -285,7 +289,7 @@ const baseCip30WalletApi = (
285289
},
286290
// eslint-disable-next-line max-statements, sonarjs/cognitive-complexity,complexity
287291
getCollateral: async (
288-
_: SenderContext,
292+
{ sender }: SenderContext,
289293
{ amount = new Serialization.Value(MAX_COLLATERAL_AMOUNT).toCbor() }: { amount?: Cbor } = {}
290294
): Promise<
291295
Cbor[] | null
@@ -300,6 +304,7 @@ const baseCip30WalletApi = (
300304
if (available.length > 0 && !!confirmationCallback.getCollateral) {
301305
// available UTxOs could be set as collateral based on user preference
302306
return await getCollateralCallback(
307+
sender,
303308
getFilterAmount(amount),
304309
available,
305310
confirmationCallback.getCollateral,
@@ -328,7 +333,13 @@ const baseCip30WalletApi = (
328333
// if no collateral available by amount in unspendables, return callback if provided to set unspendables and return in the callback
329334

330335
if (available.length > 0 && !!confirmationCallback.getCollateral) {
331-
return await getCollateralCallback(filterAmount, available, confirmationCallback.getCollateral, logger);
336+
return await getCollateralCallback(
337+
sender,
338+
filterAmount,
339+
available,
340+
confirmationCallback.getCollateral,
341+
logger
342+
);
332343
}
333344

334345
throw new ApiError(APIErrorCode.Refused, 'not enough coins in configured collateral UTxOs');

packages/wallet/test/integration/cip30mapping.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,9 @@ describe('cip30', () => {
349349
amount: 5_000_000n,
350350
utxos: sortedUtxosWithLowCoins
351351
},
352+
sender: {
353+
url: 'https://lace.io'
354+
},
352355
type: 'get_collateral'
353356
});
354357

@@ -363,6 +366,9 @@ describe('cip30', () => {
363366
amount: 5_000_000n,
364367
utxos: sortedUtxosWithLowCoins
365368
},
369+
sender: {
370+
url: 'https://lace.io'
371+
},
366372
type: 'get_collateral'
367373
});
368374

0 commit comments

Comments
 (0)