refactor(wallet2): async job for fetching crypto services moved to buy/sell controller

Async task for fetching crypto services is temporary moved because of other
changes we need to apply during the refactor phase. It will be moved to
appropriate service at the end.
This commit is contained in:
Sale Djenic 2021-11-16 14:01:55 +01:00
parent dafb457a49
commit 141b664a0c
1 changed files with 35 additions and 1 deletions

View File

@ -3,11 +3,28 @@ import NimQml, json, strutils, chronicles
import service_model, service_item
import ../../../../../app_service/[main]
import ../../../../../app_service/tasks/[qt, threadpool]
import status/[status, wallet2]
import status/statusgo_backend/wallet as status_wallet
logScope:
topics = "app-wallet2-crypto-service"
#################################################
# Async request for the list of services to buy/sell crypto
#################################################
const asyncGetCryptoServicesTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[QObjectTaskArg](argEncoded)
var success: bool
let response = status_wallet.fetchCryptoServices(success)
var list: JsonNode
if(success):
list = response.parseJson()["result"]
arg.finish($list)
QtObject:
type CryptoServiceController* = ref object of QObject
status: Status
@ -37,11 +54,28 @@ QtObject:
QtProperty[QVariant] cryptoServiceModel:
read = getCryptoServiceModel
#################################################
# This part is moved here only cause we want to get rid of it from the `app_service`
# This will be done in appropriate refactored service, the same way as async things are done
# in other services.
proc onAsyncFetchCryptoServices*(self: CryptoServiceController, response: string) {.slot.} =
self.status.wallet2.onAsyncFetchCryptoServices(response)
proc asyncFetchCryptoServices*(self: CryptoServiceController) =
## Asynchronous request for the list of services to buy/sell crypto.
let arg = QObjectTaskArg(
tptr: cast[ByteAddress](asyncGetCryptoServicesTask),
vptr: cast[ByteAddress](self.vptr),
slot: "onAsyncFetchCryptoServices"
)
self.appService.threadpool.start(arg)
#################################################
proc fetchCryptoServicesFetched*(self:CryptoServiceController) {.signal.}
proc fetchCryptoServices*(self: CryptoServiceController) {.slot.} =
if(not self.servicesFetched):
self.appService.walletService.asyncFetchCryptoServices()
self.asyncFetchCryptoServices()
else:
self.fetchCryptoServicesFetched()