Skip to content

Commit

Permalink
fix: make MarketplaceListingFilled.price nullable (#1336)
Browse files Browse the repository at this point in the history
* make MarketplaceListingFilled.price nullable

* make codegen

* update event

* update

* fix

* add TODO
  • Loading branch information
justraman authored Oct 7, 2024
1 parent d01a4b6 commit 2bc2841
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ type MarketplaceListingFilled {
amountFilled: BigInt!
amountRemaining: BigInt!
protocolFee: BigInt!
price: BigInt!
#TODO: make me required
price: BigInt
royalty: BigInt!
}

Expand Down
5 changes: 4 additions & 1 deletion src/mappings/marketplace/events/counter_offer_answered.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ export async function counterOfferAnswered(
assert(listing.state.listingType === ListingType.Offer, 'Listing is not an offer')
listing.updatedAt = new Date(block.timestamp ?? 0)

const counterOffer = await ctx.store.findOneByOrFail(CounterOffer, { id: `${listing.id}-${account.id}` })

if (data.response.__kind === 'Counter') {
const counterOffer = await ctx.store.findOneByOrFail(CounterOffer, { id: `${listing.id}-${account.id}` })
counterOffer.buyerPrice = data.response.value

await ctx.store.save(counterOffer)
Expand All @@ -127,6 +128,8 @@ export async function counterOfferAnswered(
type: listing.type.toString(),
takeAssetId: listing.takeAssetId.id,
},
buyerPrice: counterOffer.buyerPrice?.toString(),
sellerPrice: counterOffer.sellerPrice?.toString(),
response: data.response.__kind,
account: { id: account.id },
extrinsic: item.extrinsic.id,
Expand Down
11 changes: 5 additions & 6 deletions src/model/generated/_marketplaceListingFilled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class MarketplaceListingFilled {
private _amountFilled!: bigint
private _amountRemaining!: bigint
private _protocolFee!: bigint
private _price!: bigint
private _price!: bigint | undefined | null
private _royalty!: bigint

constructor(props?: Partial<Omit<MarketplaceListingFilled, 'toJSON'>>, json?: any) {
Expand All @@ -21,7 +21,7 @@ export class MarketplaceListingFilled {
this._amountFilled = marshal.bigint.fromJSON(json.amountFilled)
this._amountRemaining = marshal.bigint.fromJSON(json.amountRemaining)
this._protocolFee = marshal.bigint.fromJSON(json.protocolFee)
this._price = marshal.bigint.fromJSON(json.price)
this._price = json.price == null ? undefined : marshal.bigint.fromJSON(json.price)
this._royalty = marshal.bigint.fromJSON(json.royalty)
}
}
Expand Down Expand Up @@ -71,12 +71,11 @@ export class MarketplaceListingFilled {
this._protocolFee = value
}

get price(): bigint {
assert(this._price != null, 'uninitialized access')
get price(): bigint | undefined | null {
return this._price
}

set price(value: bigint) {
set price(value: bigint | undefined | null) {
this._price = value
}

Expand All @@ -97,7 +96,7 @@ export class MarketplaceListingFilled {
amountFilled: marshal.bigint.toJSON(this.amountFilled),
amountRemaining: marshal.bigint.toJSON(this.amountRemaining),
protocolFee: marshal.bigint.toJSON(this.protocolFee),
price: marshal.bigint.toJSON(this.price),
price: this.price == null ? undefined : marshal.bigint.toJSON(this.price),
royalty: marshal.bigint.toJSON(this.royalty),
}
}
Expand Down

0 comments on commit 2bc2841

Please sign in to comment.