From 2c043b4b21e4476d322fc5019536283785f7f436 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Sat, 18 Jun 2022 11:24:39 -0300 Subject: [PATCH] Minor refactoring --- .../resources/help/getavgbsqprice-help.txt | 2 +- .../bisq/daemon/grpc/GrpcPriceService.java | 26 +++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/core/src/main/resources/help/getavgbsqprice-help.txt b/core/src/main/resources/help/getavgbsqprice-help.txt index 8a8454d5e2..c87aaa1865 100644 --- a/core/src/main/resources/help/getavgbsqprice-help.txt +++ b/core/src/main/resources/help/getavgbsqprice-help.txt @@ -2,7 +2,7 @@ getavgbsqprice NAME ---- -getavgbsqprice - get average BSQ price in btc and usd +getavgbsqprice - get average bsq price in btc and usd SYNOPSIS -------- diff --git a/daemon/src/main/java/bisq/daemon/grpc/GrpcPriceService.java b/daemon/src/main/java/bisq/daemon/grpc/GrpcPriceService.java index 145f972d57..158cb80605 100644 --- a/daemon/src/main/java/bisq/daemon/grpc/GrpcPriceService.java +++ b/daemon/src/main/java/bisq/daemon/grpc/GrpcPriceService.java @@ -88,17 +88,7 @@ class GrpcPriceService extends PriceImplBase { try { var days = req.getDays(); Tuple2 prices = coreApi.getAverageBsqTradePrice(days); - var usdPrice = new BigDecimal(prices.first.toString()) - .setScale(Fiat.SMALLEST_UNIT_EXPONENT, RoundingMode.HALF_UP); - var btcPrice = new BigDecimal(prices.second.toString()) - .setScale(Altcoin.SMALLEST_UNIT_EXPONENT, RoundingMode.HALF_UP); - var proto = AverageBsqTradePrice.newBuilder() - .setUsdPrice(usdPrice.toString()) - .setBtcPrice(btcPrice.toString()) - .build(); - var reply = GetAverageBsqTradePriceReply.newBuilder() - .setPrice(proto) - .build(); + var reply = buildGetAverageBsqTradePriceReply(prices); responseObserver.onNext(reply); responseObserver.onCompleted(); } catch (Throwable cause) { @@ -121,4 +111,18 @@ class GrpcPriceService extends PriceImplBase { }} ))); } + + private GetAverageBsqTradePriceReply buildGetAverageBsqTradePriceReply(Tuple2 prices) { + var usdPrice = new BigDecimal(prices.first.toString()) + .setScale(Fiat.SMALLEST_UNIT_EXPONENT, RoundingMode.HALF_UP); + var btcPrice = new BigDecimal(prices.second.toString()) + .setScale(Altcoin.SMALLEST_UNIT_EXPONENT, RoundingMode.HALF_UP); + var proto = AverageBsqTradePrice.newBuilder() + .setUsdPrice(usdPrice.toString()) + .setBtcPrice(btcPrice.toString()) + .build(); + return GetAverageBsqTradePriceReply.newBuilder() + .setPrice(proto) + .build(); + } }