Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(@desktop/wallet): SwapModal: refresh currency price as well when fetching proposal #15752

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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