feat(deal-ticket): get discounts for estimation from previous epoch (#5163)

This commit is contained in:
Bartłomiej Głownia 2023-11-01 11:09:56 +01:00 committed by GitHub
parent deea63fa5e
commit 673c896e2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 7 deletions

View File

@ -6,7 +6,7 @@ import type { EstimateFeesQuery } from './__generated__/EstimateOrder';
const data: EstimateFeesQuery = { const data: EstimateFeesQuery = {
epoch: { epoch: {
id: '2', id: '3',
}, },
volumeDiscountStats: { volumeDiscountStats: {
edges: [ edges: [
@ -117,7 +117,7 @@ describe('useEstimateFees', () => {
}); });
}); });
it('returns 0 discounts if discount stats are not at the current epoch', () => { it('returns 0 discounts if discount stats are not at the current epoch -1', () => {
const { result } = renderHook(() => const { result } = renderHook(() =>
useEstimateFees( useEstimateFees(
{ {
@ -136,7 +136,7 @@ describe('useEstimateFees', () => {
}); });
it('returns discounts', () => { it('returns discounts', () => {
data.epoch.id = '1'; data.epoch.id = '2';
const { result } = renderHook(() => const { result } = renderHook(() =>
useEstimateFees( useEstimateFees(
{ {

View File

@ -34,14 +34,13 @@ export const useEstimateFees = (
skip: !pubKey || !order?.size || !order?.price || order.postOnly, skip: !pubKey || !order?.size || !order?.price || order.postOnly,
}); });
const data = loading ? currentData || previousData : currentData; const data = loading ? currentData || previousData : currentData;
const atEpoch = (Number(data?.epoch.id) || 0) - 1;
const volumeDiscountFactor = const volumeDiscountFactor =
(data?.volumeDiscountStats.edges[0]?.node.atEpoch.toString() === (data?.volumeDiscountStats.edges[0]?.node.atEpoch === atEpoch &&
data?.epoch.id &&
data?.volumeDiscountStats.edges[0]?.node.discountFactor) || data?.volumeDiscountStats.edges[0]?.node.discountFactor) ||
'0'; '0';
const referralDiscountFactor = const referralDiscountFactor =
(data?.referralSetStats.edges[0]?.node.atEpoch.toString() === (data?.referralSetStats.edges[0]?.node.atEpoch === atEpoch &&
data?.epoch.id &&
data?.referralSetStats.edges[0]?.node.discountFactor) || data?.referralSetStats.edges[0]?.node.discountFactor) ||
'0'; '0';
if (order?.postOnly) { if (order?.postOnly) {