Skip to content

Commit bf7a2d2

Browse files
authored
Merge pull request #9102 from BitGo/CHALO-699
feat: allow null value in contractId field of allocate
2 parents e0ae314 + 4797e8d commit bf7a2d2

3 files changed

Lines changed: 27 additions & 7 deletions

File tree

modules/sdk-coin-canton/src/lib/allocationAllocateBuilder.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class AllocationAllocateBuilder extends TransactionBuilder {
1010
private _amount: number;
1111
private _token: string;
1212
private _operatorId: string;
13-
private _contractId: string;
13+
private _contractId: string | null | undefined;
1414
private _tradeId: string;
1515
private _transferLegId: string;
1616
private _allocateBefore: string;
@@ -116,11 +116,11 @@ export class AllocationAllocateBuilder extends TransactionBuilder {
116116
* @returns The current builder instance for chaining.
117117
* @throws Error if id is empty.
118118
*/
119-
contractId(id: string): this {
120-
if (!id || !id.trim()) {
119+
contractId(id: string | null): this {
120+
if (id !== null && (!id || !id.trim())) {
121121
throw new Error('contractId must be a non-empty string');
122122
}
123-
this._contractId = id.trim();
123+
this._contractId = id === null ? null : id.trim();
124124
return this;
125125
}
126126

@@ -231,7 +231,7 @@ export class AllocationAllocateBuilder extends TransactionBuilder {
231231
amount: this._amount,
232232
token: this._token,
233233
operatorId: this._operatorId,
234-
contractId: this._contractId,
234+
...(this._contractId !== null && this._contractId !== undefined && { contractId: this._contractId }),
235235
tradeId: this._tradeId,
236236
transferLegId: this._transferLegId,
237237
allocateBefore: this._allocateBefore,
@@ -256,7 +256,7 @@ export class AllocationAllocateBuilder extends TransactionBuilder {
256256
if (!this._amount) throw new Error('amount is missing');
257257
if (!this._token) throw new Error('token is missing');
258258
if (!this._operatorId) throw new Error('operatorId is missing');
259-
if (!this._contractId) throw new Error('contractId is missing');
259+
if (this._contractId === undefined) throw new Error('contractId is missing');
260260
if (!this._tradeId) throw new Error('tradeId is missing');
261261
if (!this._transferLegId) throw new Error('transferLegId is missing');
262262
if (!this._allocateBefore) throw new Error('allocateBefore is missing');

modules/sdk-coin-canton/src/lib/iface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export interface CantonAllocationAllocateRequest {
194194
amount: number;
195195
token: string;
196196
operatorId: string;
197-
contractId: string;
197+
contractId?: string;
198198
tradeId: string;
199199
transferLegId: string;
200200
allocateBefore: string;

modules/sdk-coin-canton/test/unit/builder/allocationAllocate/allocationAllocateBuilder.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,26 @@ describe('AllocationAllocate Builder', () => {
295295
assert.throws(() => txBuilder.contractId(''), /contractId must be a non-empty string/);
296296
});
297297

298+
it('should accept null contractId and omit it from the request object', function () {
299+
const txBuilder = new AllocationAllocateBuilder(coins.get('tcanton'));
300+
const tx = new Transaction(coins.get('tcanton'));
301+
txBuilder.initBuilder(tx);
302+
txBuilder
303+
.commandId(commandId)
304+
.amount(amount)
305+
.token(token)
306+
.operatorId(operatorId)
307+
.contractId(null)
308+
.tradeId(tradeId)
309+
.transferLegId(transferLegId)
310+
.allocateBefore(allocateBefore)
311+
.settleBefore(settleBefore)
312+
.receiverPartyId(receiverPartyId)
313+
.senderPartyId(senderPartyId);
314+
const requestObj = txBuilder.toRequestObject();
315+
assert.equal(requestObj.contractId, undefined, 'contractId should be absent when set to null');
316+
});
317+
298318
it('should throw if tradeId is an empty string', function () {
299319
const txBuilder = new AllocationAllocateBuilder(coins.get('tcanton'));
300320
assert.throws(() => txBuilder.tradeId(''), /tradeId must be a non-empty string/);

0 commit comments

Comments
 (0)