From 5a739b6af5a3160274858fc2c77fe7b4c2ad151e Mon Sep 17 00:00:00 2001 From: bayge Date: Mon, 30 Sep 2024 22:57:46 +0930 Subject: [PATCH] Set value usd to 0 if we don't have backdata --- cmd/graphql.ethereum/graph/schema.resolvers.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/graphql.ethereum/graph/schema.resolvers.go b/cmd/graphql.ethereum/graph/schema.resolvers.go index 6c2d4c24..633df917 100644 --- a/cmd/graphql.ethereum/graph/schema.resolvers.go +++ b/cmd/graphql.ethereum/graph/schema.resolvers.go @@ -133,8 +133,13 @@ func (r *amountResolver) ValueUsd(ctx context.Context, obj *model.Amount) (strin Where("pool = ?", obj.Token). First(&finalTick). Error - if err != nil { + switch { + case errors.Is(err, ErrRecordNotFound): + return "0", nil + case err != nil: return "", err + default: + // Do nothing } sqrtPrice := math.GetSqrtRatioAtTick(finalTick.FinalTick.Big()) price := math.GetPriceAtSqrtRatio(sqrtPrice)