-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from XYOracleNetwork/feature/subtotal-diviner-…
…in-discounts Coupon Condition Helpers
- Loading branch information
Showing
6 changed files
with
134 additions
and
65 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...load/packages/payments/src/Discount/Payload/Coupon/Conditions/AppraisalAmountCondition.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* eslint-disable unicorn/no-thenable */ | ||
import { SchemaSchema } from '@xyo-network/schema-payload-plugin' | ||
|
||
import type { Condition } from '../types/index.ts' | ||
|
||
/** | ||
* Creates a coupon condition that requires an appraisal amount below a certain value | ||
* @param maximumAppraisalAmount The maximum appraisal amount | ||
* @returns A condition that requires an appraisal amount below a certain value | ||
*/ | ||
export const createConditionForMaximumAppraisalAmount = (maximumAppraisalAmount: number): Condition => { | ||
return { | ||
schema: SchemaSchema, | ||
definition: { | ||
allOf: [ | ||
{ | ||
type: 'array', | ||
contains: { | ||
type: 'object', | ||
properties: { | ||
schema: { type: 'string', const: 'network.xyo.escrow.terms' }, | ||
appraisals: { type: 'array', minItems: 1 }, | ||
}, | ||
required: ['schema', 'appraisals'], | ||
}, | ||
}, | ||
{ | ||
type: 'array', | ||
contains: { | ||
type: 'object', | ||
properties: { schema: { type: 'string', const: 'network.xyo.hash.lease.estimate' } }, | ||
required: ['schema'], | ||
}, | ||
items: { | ||
type: 'object', | ||
if: { properties: { schema: { type: 'string', const: 'network.xyo.hash.lease.estimate' } } }, | ||
then: { properties: { price: { type: 'number', maximum: maximumAppraisalAmount } }, required: ['price'] }, | ||
}, | ||
}, | ||
], | ||
}, | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ayload/packages/payments/src/Discount/Payload/Coupon/Conditions/AssetQuantityCondition.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { SchemaSchema } from '@xyo-network/schema-payload-plugin' | ||
|
||
import type { Condition } from '../types/index.ts' | ||
|
||
/** | ||
* Returns a coupon condition that requires a minimum quantity of assets | ||
* @param minimumAssetQuantity The minimum quantity of assets required | ||
* @returns A condition that requires a minimum quantity of assets | ||
*/ | ||
export const createConditionForMinimumAssetQuantity = (minimumAssetQuantity: number): Condition => { | ||
return { | ||
schema: SchemaSchema, | ||
definition: { | ||
type: 'array', | ||
contains: { | ||
type: 'object', | ||
properties: { | ||
schema: { type: 'string', const: 'network.xyo.escrow.terms' }, | ||
assets: { type: 'array', minItems: minimumAssetQuantity }, | ||
}, | ||
required: ['schema', 'assets'], | ||
}, | ||
}, | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
packages/payload/packages/payments/src/Discount/Payload/Coupon/Conditions/BuyerCondition.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import type { Address } from '@xylabs/hex' | ||
import { SchemaSchema } from '@xyo-network/schema-payload-plugin' | ||
|
||
import type { Condition } from '../types/index.ts' | ||
|
||
export type BuyerCondition = Condition & { | ||
definition: { | ||
contains: { | ||
properties: { | ||
buyer: { | ||
items: { | ||
const: Address | ||
type: 'string' | ||
} | ||
minItems: 1 | ||
type: 'array' | ||
} | ||
schema: { const: 'network.xyo.escrow.terms'; type: 'string' } | ||
} | ||
required: ['schema', 'buyer'] | ||
type: 'object' | ||
} | ||
type: 'array' | ||
} | ||
schema: SchemaSchema | ||
} | ||
|
||
/** | ||
* Creates a coupon condition that requires a specific buyer | ||
* @param buyer The buyer's address | ||
* @returns A coupon condition that requires a specific buyer | ||
*/ | ||
export const createConditionForRequiredBuyer = (buyer: Address): BuyerCondition => { | ||
return { | ||
schema: SchemaSchema, | ||
definition: { | ||
type: 'array', | ||
contains: { | ||
type: 'object', | ||
properties: { | ||
schema: { type: 'string', const: 'network.xyo.escrow.terms' }, | ||
buyer: { | ||
type: 'array', items: { type: 'string', const: buyer }, minItems: 1, | ||
}, | ||
}, | ||
required: ['schema', 'buyer'], | ||
}, | ||
}, | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/payload/packages/payments/src/Discount/Payload/Coupon/Conditions/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './AppraisalAmountCondition.ts' | ||
export * from './AssetQuantityCondition.ts' | ||
export * from './BuyerCondition.ts' |
1 change: 1 addition & 0 deletions
1
packages/payload/packages/payments/src/Discount/Payload/Coupon/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters