Skip to content

Commit

Permalink
feat(@desktop/wallet): SwapModal: refresh currency price as well when…
Browse files Browse the repository at this point in the history
… fetching proposal

fixes #15454
  • Loading branch information
Khushboo-dev-cpp committed Aug 16, 2024
1 parent de78725 commit 6ddaa2e
Show file tree
Hide file tree
Showing 5 changed files with 19 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
10 changes: 9 additions & 1 deletion src/app_service/service/token/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -564,4 +564,12 @@ QtObject:
raise newException(CatchableError, response.error.message)
self.fetchTokenPreferences()
except Exception as e:
error "error: ", procName="updateTokenPreferences", errName=e.name, errDesription=e.msg
error "error: ", prproc updateTokenPrices*(self: Service, updatedPrices: Table[string, float64]) =
for tokenSymbol, price in updatedPrices:
self.tokenPriceTable[tokenSymbol] = price
self.events.emit(SIGNAL_TOKENS_PRICES_UPDATED, Args())ocName="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.suggestedRoutesV2Ready(data.uuid, data.bestRoute, data.bestRouteRaw, data.errorCode, data.error)

self.events.on(PendingTransactionTypeDto.WalletTransfer.event) do(e: Args):
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 @@ -233,6 +233,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 6ddaa2e

Please sign in to comment.