Updating or Creating OrderResue provider fee

This commit is contained in:
Jamie Hewitt 2022-07-04 11:49:24 +01:00
parent 3dac319c0e
commit 0f124d01dd
2 changed files with 19 additions and 8 deletions

View File

@ -249,6 +249,7 @@ type OrderReuse @entity {
createdTimestamp: BigInt!
tx: String!
block: BigInt!
providerFee: String
}
type Order @entity {
"transaction hash - token address - from address"

View File

@ -199,12 +199,6 @@ export function handleNewPaymentCollector(event: NewPaymentCollector): void {
}
export function handleProviderFee(event: ProviderFee): void {
const order = getOrder(
event.transaction.hash.toHex(),
event.address.toHex(),
event.transaction.from.toHex()
)
const providerFee: string = `{providerFeeAddress: ${event.params.providerFeeAddress.toHex()}, providerFeeToken: ${event.params.providerFeeToken.toHex()}, providerFeeAmount: ${
event.params.providerFeeAmount
}, providerData: ${event.params.providerData.toHexString()}, v: ${
@ -214,8 +208,24 @@ export function handleProviderFee(event: ProviderFee): void {
}
}`
order.providerFee = providerFee
order.save()
const orderId = getOrderId(
event.transaction.hash.toHex(),
event.address.toHex(),
event.transaction.from.toHex()
)
const order = Order.load(orderId)
let orderReuse = OrderReuse.load(event.transaction.hash.toHex())
if (order) {
order.providerFee = providerFee
order.save()
} else if (orderReuse) {
orderReuse.providerFee = providerFee
orderReuse.save()
} else {
orderReuse = new OrderReuse(event.transaction.hash.toHex())
orderReuse.providerFee = providerFee
orderReuse.save()
}
}
// export function handlePublishMarketFees(event: PublishMarketFees): void {