Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions modules/sdk-coin-canton/src/lib/allocationAllocateBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class AllocationAllocateBuilder extends TransactionBuilder {
private _amount: number;
private _token: string;
private _operatorId: string;
private _contractId: string;
private _contractId: string | null | undefined;
private _tradeId: string;
private _transferLegId: string;
private _allocateBefore: string;
Expand Down Expand Up @@ -116,11 +116,11 @@ export class AllocationAllocateBuilder extends TransactionBuilder {
* @returns The current builder instance for chaining.
* @throws Error if id is empty.
*/
contractId(id: string): this {
if (!id || !id.trim()) {
contractId(id: string | null): this {
if (id !== null && (!id || !id.trim())) {
throw new Error('contractId must be a non-empty string');
}
this._contractId = id.trim();
this._contractId = id === null ? null : id.trim();
return this;
}

Expand Down Expand Up @@ -231,7 +231,7 @@ export class AllocationAllocateBuilder extends TransactionBuilder {
amount: this._amount,
token: this._token,
operatorId: this._operatorId,
contractId: this._contractId,
...(this._contractId !== null && this._contractId !== undefined && { contractId: this._contractId }),
tradeId: this._tradeId,
transferLegId: this._transferLegId,
allocateBefore: this._allocateBefore,
Expand All @@ -256,7 +256,7 @@ export class AllocationAllocateBuilder extends TransactionBuilder {
if (!this._amount) throw new Error('amount is missing');
if (!this._token) throw new Error('token is missing');
if (!this._operatorId) throw new Error('operatorId is missing');
if (!this._contractId) throw new Error('contractId is missing');
if (this._contractId === undefined) throw new Error('contractId is missing');
if (!this._tradeId) throw new Error('tradeId is missing');
if (!this._transferLegId) throw new Error('transferLegId is missing');
if (!this._allocateBefore) throw new Error('allocateBefore is missing');
Expand Down
2 changes: 1 addition & 1 deletion modules/sdk-coin-canton/src/lib/iface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export interface CantonAllocationAllocateRequest {
amount: number;
token: string;
operatorId: string;
contractId: string;
contractId?: string;
tradeId: string;
transferLegId: string;
allocateBefore: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,26 @@ describe('AllocationAllocate Builder', () => {
assert.throws(() => txBuilder.contractId(''), /contractId must be a non-empty string/);
});

it('should accept null contractId and omit it from the request object', function () {
const txBuilder = new AllocationAllocateBuilder(coins.get('tcanton'));
const tx = new Transaction(coins.get('tcanton'));
txBuilder.initBuilder(tx);
txBuilder
.commandId(commandId)
.amount(amount)
.token(token)
.operatorId(operatorId)
.contractId(null)
.tradeId(tradeId)
.transferLegId(transferLegId)
.allocateBefore(allocateBefore)
.settleBefore(settleBefore)
.receiverPartyId(receiverPartyId)
.senderPartyId(senderPartyId);
const requestObj = txBuilder.toRequestObject();
assert.equal(requestObj.contractId, undefined, 'contractId should be absent when set to null');
});

it('should throw if tradeId is an empty string', function () {
const txBuilder = new AllocationAllocateBuilder(coins.get('tcanton'));
assert.throws(() => txBuilder.tradeId(''), /tradeId must be a non-empty string/);
Expand Down
Loading