Skip to content

Commit 3ec61d7

Browse files
authored
[CHIA-4224] Added offer_only option to create_offer_for_ids (#2506)
* Added `offer_only` option to `create_offer_for_ids` * Fixed type issue * Add `offer_only` to WalletConnect registry * Fixed type issue
1 parent 6746a71 commit 3ec61d7

3 files changed

Lines changed: 42 additions & 13 deletions

File tree

packages/api/src/services/WalletService.ts

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,35 @@ export type AllowUnsyncedArg = {
3333
allowUnsynced?: boolean;
3434
};
3535

36+
export type CreateOfferForIdsArgs = {
37+
offer: { [key: string]: number | BigNumber };
38+
fee: number | BigNumber;
39+
driverDict: any;
40+
validateOnly?: boolean;
41+
disableJSONFormatting?: boolean;
42+
maxTime?: number;
43+
offerOnly?: boolean;
44+
extraConditions?: any[];
45+
coinIds?: string[];
46+
} & AllowUnsyncedArg;
47+
48+
export type CreateOfferForIdsResponse = {
49+
offer: string;
50+
tradeRecord: TradeRecord;
51+
};
52+
53+
export type CreateOfferForIdsOfferOnlyResponse = {
54+
offer: string;
55+
};
56+
57+
export type CreateOfferForIdsResult<TArgs extends CreateOfferForIdsArgs> = TArgs extends { offerOnly: true }
58+
? CreateOfferForIdsOfferOnlyResponse
59+
: TArgs extends { offerOnly: false }
60+
? CreateOfferForIdsResponse
61+
: TArgs extends { offerOnly: boolean }
62+
? CreateOfferForIdsResponse | CreateOfferForIdsOfferOnlyResponse
63+
: CreateOfferForIdsResponse;
64+
3665
export default class Wallet extends Service {
3766
constructor(client: Client, options?: Options) {
3867
super(ServiceName.WALLET, client, options);
@@ -312,20 +341,9 @@ export default class Wallet extends Service {
312341
return this.command<{ myOffersCount: number; takenOffersCount: number; total: number }>('get_offers_count');
313342
}
314343

315-
async createOfferForIds(
316-
args: {
317-
offer: { [key: string]: number | BigNumber };
318-
fee: number | BigNumber;
319-
driverDict: any;
320-
validateOnly?: boolean;
321-
disableJSONFormatting?: boolean;
322-
maxTime?: number;
323-
extraConditions?: any[];
324-
coinIds?: string[];
325-
} & AllowUnsyncedArg,
326-
) {
344+
async createOfferForIds<TArgs extends CreateOfferForIdsArgs>(args: TArgs): Promise<CreateOfferForIdsResult<TArgs>> {
327345
const { disableJSONFormatting, driverDict, extraConditions, coinIds, ...restArgs } = args;
328-
return this.command<{ offer: string; tradeRecord: TradeRecord }>(
346+
return this.command<CreateOfferForIdsResult<TArgs>>(
329347
'create_offer_for_ids',
330348
{ driver_dict: driverDict, extra_conditions: extraConditions, coin_ids: coinIds, ...restArgs },
331349
false,

packages/gui/src/electron/constants/commandRegistry.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ describe('validateDappParams', () => {
330330
expect(() => validateDappParams('chia_sendTransaction', { wallet_id: 1 })).not.toThrow();
331331
});
332332

333+
it('allows create_offer_for_ids to request offer-only responses', () => {
334+
expect(() => validateDappParams('chia_createOfferForIds', { offer: {}, offer_only: true })).not.toThrow();
335+
});
336+
333337
it('handler-routed commands enforce the same allowlist', () => {
334338
expect(() => validateDappParams('chia_addCATToken', { asset_id: 'abc', name: 'My CAT' })).not.toThrow();
335339
expectThrow(

packages/gui/src/electron/constants/commandRegistry.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,13 @@ const SCHEMAS: Record<string, CommandSchema> = {
399399
isOptional: true,
400400
dappAllowed: true,
401401
},
402+
{
403+
name: 'offer_only',
404+
label: () => i18n._(/* i18n */ { id: 'Omit transactions data' }),
405+
type: 'bool',
406+
isOptional: true,
407+
dappAllowed: true,
408+
},
402409
{
403410
name: 'extra_conditions',
404411
label: () => i18n._(/* i18n */ { id: 'Extra Conditions' }),

0 commit comments

Comments
 (0)