Skip to content

Commit

Permalink
feat: fees update integration after calculating the initial route
Browse files Browse the repository at this point in the history
  • Loading branch information
saledjenic authored and Khushboo-dev-cpp committed Sep 12, 2024
1 parent 1a3b75f commit 8dc067e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/app/core/signals/remote_signals/wallet.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import json, options, chronicles
import json, options, chronicles, Tables

import base
import signal_type
Expand All @@ -24,6 +24,7 @@ type WalletSignal* = ref object of Signal
bestRoute*: seq[TransactionPathDtoV2]
error*: string
errorCode*: string
updatedPrices*: Table[string, float64]

proc fromEvent*(T: type WalletSignal, signalType: SignalType, jsonSignal: JsonNode): WalletSignal =
result = WalletSignal()
Expand Down Expand Up @@ -67,6 +68,10 @@ proc fromEvent*(T: type WalletSignal, signalType: SignalType, jsonSignal: JsonNo
result.error = errorResponseJsonNode["details"].getStr
if errorResponseJsonNode.contains("code"):
result.errorCode = errorResponseJsonNode["code"].getStr
result.updatedPrices = initTable[string, float64]()
if event.contains("UpdatedPrices"):
for tokenSymbol, price in event["UpdatedPrices"].pairs():
result.updatedPrices[tokenSymbol] = price.getFloat
except:
error "Error parsing best route"
return
5 changes: 5 additions & 0 deletions src/app_service/service/token/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -565,3 +565,8 @@ QtObject:
self.fetchTokenPreferences()
except Exception as e:
error "error: ", procName="updateTokenPreferences", errName=e.name, errDesription=e.msg

proc updateTokenPrices*(self: Service, updatedPrices: Table[string, float64]) =
for tokenSymbol, price in updatedPrices:
self.tokenPriceTable[tokenSymbol] = price
self.events.emit(SIGNAL_TOKENS_PRICES_UPDATED, Args())
1 change: 1 addition & 0 deletions src/app_service/service/transaction/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ QtObject:

self.events.on(SignalType.WalletSuggestedRoutes.event) do(e:Args):
var data = WalletSignal(e)
self.tokenService.updateTokenPrices(data.updatedPrices)
self.suggestedRoutesReady(data.uuid, data.bestRoute, data.bestRouteRaw, data.errorCode, data.error)

self.events.on(PendingTransactionTypeDto.WalletTransfer.event) do(e: Args):
Expand Down
6 changes: 5 additions & 1 deletion storybook/qmlTests/tests/tst_SwapModal.qml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Item {

// verfy input and output panels
verify(!payPanel.mainInputLoading)
verify(!payPanel.bottomTextLoading)
verify(payPanel.bottomTextLoading)
compare(payPanel.selectedHoldingId, root.swapFormData.fromTokensKey)
compare(payPanel.value, Number(root.swapFormData.fromTokenAmount))
compare(payPanel.rawValue, SQUtils.AmountsArithmetic.fromNumber(root.swapFormData.fromTokenAmount, root.swapAdaptor.fromToken.decimals).toString())
Expand Down Expand Up @@ -808,6 +808,8 @@ Item {
// verfy input and output panels
waitForRendering(receivePanel)
verify(payPanel.valueValid)
verify(!payPanel.mainInputLoading)
verify(!payPanel.bottomTextLoading)
verify(!receivePanel.mainInputLoading)
verify(!receivePanel.bottomTextLoading)
verify(!receivePanel.interactive)
Expand Down Expand Up @@ -858,6 +860,8 @@ Item {
// verfy input and output panels
waitForRendering(receivePanel)
verify(payPanel.valueValid)
verify(!payPanel.mainInputLoading)
verify(!payPanel.bottomTextLoading)
verify(!receivePanel.mainInputLoading)
verify(!receivePanel.bottomTextLoading)
verify(!receivePanel.interactive)
Expand Down
2 changes: 2 additions & 0 deletions ui/app/AppLayouts/Wallet/popups/swap/SwapModal.qml
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ StatusDialog {
swapSide: SwapInputPanel.SwapSide.Pay
swapExchangeButtonWidth: swapExchangeButton.width

bottomTextLoading: root.swapAdaptor.swapProposalLoading

onSelectedHoldingIdChanged: root.swapInputParamsForm.fromTokensKey = selectedHoldingId

onRawValueChanged: {
Expand Down

0 comments on commit 8dc067e

Please sign in to comment.