Skip to content

Commit

Permalink
feat(@desktop/wallet): Implement connection error screens
Browse files Browse the repository at this point in the history
fixes #9835
  • Loading branch information
Khushboo-dev-cpp committed Mar 20, 2023
1 parent f9e1018 commit 4fee741
Show file tree
Hide file tree
Showing 33 changed files with 514 additions and 85 deletions.
3 changes: 2 additions & 1 deletion src/app/modules/main/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ proc newModule*[T](
result.walletSectionModule = wallet_section_module.newModule(
result, events, tokenService, currencyService,
transactionService, collectible_service, walletAccountService,
settingsService, savedAddressService, networkService, accountsService, keycardService
settingsService, savedAddressService, networkService, accountsService,
keycardService, nodeService, networkConnectionService
)
result.browserSectionModule = browser_section_module.newModule(
result, events, bookmarkService, settingsService, networkService,
Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/main/network_connection/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ method viewDidLoad*(self: Module) =
self.checkIfModuleDidLoad()

method networkConnectionStatusUpdate*(self: Module, website: string, completelyDown: bool, connectionState: int, chainIds: string, lastCheckedAt: int, timeToAutoRetryInSecs: int, withCache: bool) =
self.view.networkConnectionStatusUpdate(website, completelyDown, connectionState, chainIds, lastCheckedAt, timeToAutoRetryInSecs, withCache)
self.view.updateNetworkConnectionStatus(website, completelyDown, connectionState, chainIds, lastCheckedAt, timeToAutoRetryInSecs, withCache)

method refreshBlockchainValues*(self: Module) =
self.controller.refreshBlockchainValues()
Expand Down
101 changes: 101 additions & 0 deletions src/app/modules/main/network_connection/network_connection_item.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import NimQml, strformat

QtObject:
type NetworkConnectionItem* = ref object of QObject
completelyDown: bool
connectionState: int
chainIds: string
lastCheckedAt: int
timeToAutoRetryInSecs: int
withCache: bool

proc delete*(self: NetworkConnectionItem) =
self.QObject.delete

proc newNetworkConnectionItem*(completelyDown = false, connectionState = 0, chainIds = "", lastCheckedAt = 0, timeToAutoRetryInSecs = 0, withCache = false,): NetworkConnectionItem =
new(result, delete)
result.QObject.setup
result.completelyDown = completelyDown
result.connectionState = connectionState
result.chainIds = chainIds
result.lastCheckedAt = lastCheckedAt
result.timeToAutoRetryInSecs = timeToAutoRetryInSecs
result.withCache = withCache

proc `$`*(self: NetworkConnectionItem): string =
result = fmt"""NetworkConnectionItem[
completelyDown: {self.completelyDown},
connectionState: {self.connectionState},
chainIds: {self.chainIds},
lastCheckedAt: {self.lastCheckedAt},
timeToAutoRetryInSecs: {self.timeToAutoRetryInSecs},
withCache: {self.withCache}
]"""

proc completelyDownChanged*(self: NetworkConnectionItem) {.signal.}
proc getCompletelyDown*(self: NetworkConnectionItem): bool {.slot.} =
return self.completelyDown
QtProperty[bool] completelyDown:
read = getCompletelyDown
notify = completelyDownChanged

proc connectionStateChanged*(self: NetworkConnectionItem) {.signal.}
proc getConnectionState*(self: NetworkConnectionItem): int {.slot.} =
return self.connectionState
QtProperty[int] connectionState:
read = getConnectionState
notify = connectionStateChanged

proc chainIdsChanged*(self: NetworkConnectionItem) {.signal.}
proc getChainIds*(self: NetworkConnectionItem): string {.slot.} =
return self.chainIds
QtProperty[string] chainIds:
read = getChainIds
notify = chainIdsChanged

proc lastCheckedAtChanged*(self: NetworkConnectionItem) {.signal.}
proc getLastCheckedAt*(self: NetworkConnectionItem): int {.slot.} =
return self.lastCheckedAt
QtProperty[int] lastCheckedAt:
read = getLastCheckedAt
notify = lastCheckedAtChanged

proc timeToAutoRetryInSecsChanged*(self: NetworkConnectionItem) {.signal.}
proc getTimeToAutoRetryInSecs*(self: NetworkConnectionItem): int {.slot.} =
return self.timeToAutoRetryInSecs
QtProperty[int] timeToAutoRetryInSecs:
read = getTimeToAutoRetryInSecs
notify = timeToAutoRetryInSecsChanged

proc withCacheChanged*(self: NetworkConnectionItem) {.signal.}
proc getWithCache*(self: NetworkConnectionItem): bool {.slot.} =
return self.withCache
QtProperty[bool] withCache:
read = getWithCache
notify = withCacheChanged

proc updateValues*(self: NetworkConnectionItem, completelyDown: bool, connectionState: int,
chainIds: string, lastCheckedAt: int, timeToAutoRetryInSecs: int, withCache: bool) =
if self.completelyDown != completelyDown :
self.completelyDown = completelyDown
self.completelyDownChanged()

if self.connectionState != connectionState :
self.connectionState = connectionState
self.connectionStateChanged()

if self.chainIds != chainIds :
self.chainIds = chainIds
self.chainIdsChanged()

if self.lastCheckedAt != lastCheckedAt :
self.lastCheckedAt = lastCheckedAt
self.lastCheckedAtChanged()

if self.timeToAutoRetryInSecs != timeToAutoRetryInSecs :
self.timeToAutoRetryInSecs = timeToAutoRetryInSecs
self.timeToAutoRetryInSecsChanged()

if self.withCache != withCache :
self.withCache = withCache
self.withCacheChanged()
48 changes: 47 additions & 1 deletion src/app/modules/main/network_connection/view.nim
Original file line number Diff line number Diff line change
@@ -1,27 +1,57 @@
import NimQml

import ./io_interface
import ./network_connection_item
import ../../../../app_service/service/network_connection/service as network_connection_service

QtObject:
type
View* = ref object of QObject
delegate: io_interface.AccessInterface
blockchainNetworkConnection: NetworkConnectionItem
collectiblesNetworkConnection: NetworkConnectionItem
marketValuesNetworkConnection: NetworkConnectionItem

proc setup(self: View) =
self.QObject.setup

proc delete*(self: View) =
self.QObject.delete
self.blockchainNetworkConnection.delete
self.collectiblesNetworkConnection.delete
self.marketValuesNetworkConnection.delete

proc newView*(delegate: io_interface.AccessInterface): View =
new(result, delete)
result.delegate = delegate
result.blockchainNetworkConnection = newNetworkConnectionItem()
result.collectiblesNetworkConnection = newNetworkConnectionItem()
result.marketValuesNetworkConnection = newNetworkConnectionItem()
result.setup()

proc load*(self: View) =
self.delegate.viewDidLoad()

proc networkConnectionStatusUpdate*(self: View, website: string, completelyDown: bool, connectionState: int, chainIds: string, lastCheckedAt: int, timeToAutoRetryInSecs: int, withCache: bool) {.signal.}
proc blockchainNetworkConnectionChanged*(self:View) {.signal.}
proc getBlockchainNetworkConnection(self: View): QVariant {.slot.} =
return newQVariant(self.blockchainNetworkConnection)
QtProperty[QVariant] blockchainNetworkConnection:
read = getBlockchainNetworkConnection
notify = blockchainNetworkConnectionChanged

proc collectiblesNetworkConnectionChanged*(self:View) {.signal.}
proc getCollectiblesNetworkConnection(self: View): QVariant {.slot.} =
return newQVariant(self.collectiblesNetworkConnection)
QtProperty[QVariant] collectiblesNetworkConnection:
read = getCollectiblesNetworkConnection
notify = collectiblesNetworkConnectionChanged

proc marketValuesNetworkConnectionChanged*(self:View) {.signal.}
proc getMarketValuesNetworkConnection(self: View): QVariant {.slot.} =
return newQVariant(self.marketValuesNetworkConnection)
QtProperty[QVariant] marketValuesNetworkConnection:
read = getMarketValuesNetworkConnection
notify = marketValuesNetworkConnectionChanged

proc refreshBlockchainValues*(self: View) {.slot.} =
self.delegate.refreshBlockchainValues()
Expand All @@ -32,3 +62,19 @@ QtObject:
proc refreshCollectiblesValues*(self: View) {.slot.} =
self.delegate.refreshCollectiblesValues()

proc networkConnectionStatusUpdate*(self: View, website: string, completelyDown: bool, connectionState: int, chainIds: string, lastCheckedAt: int, timeToAutoRetryInSecs: int, withCache: bool) {.signal.}

proc updateNetworkConnectionStatus*(self: View, website: string, completelyDown: bool, connectionState: int, chainIds: string, lastCheckedAt: int, timeToAutoRetryInSecs: int, withCache: bool) =
case website:
of BLOCKCHAINS:
self.blockchainNetworkConnection.updateValues(completelyDown, connectionState, chainIds, lastCheckedAt, timeToAutoRetryInSecs, withCache)
self.blockchainNetworkConnectionChanged()
of COLLECTIBLES:
self.collectiblesNetworkConnection.updateValues(completelyDown, connectionState, chainIds, lastCheckedAt, timeToAutoRetryInSecs, withCache)
self.collectiblesNetworkConnectionChanged()
of MARKET:
self.marketValuesNetworkConnection.updateValues(completelyDown, connectionState, chainIds, lastCheckedAt, timeToAutoRetryInSecs, withCache)
self.marketValuesNetworkConnectionChanged()
self.networkConnectionStatusUpdate(website, completelyDown, connectionState, chainIds, lastCheckedAt, timeToAutoRetryInSecs, withCache)


23 changes: 22 additions & 1 deletion src/app/modules/main/wallet_section/collectibles/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ../../../../../app_service/service/collectible/service as collectible_ser
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
import ../../../../../app_service/service/network/service as network_service
import ../../../../../app_service/service/network_connection/service as network_connection_service
import ../../../../../app_service/service/node/service as node_service
import ../../../../core/eventemitter

type
Expand All @@ -13,20 +14,29 @@ type
collectibleService: collectible_service.Service
walletAccountService: wallet_account_service.Service
networkService: network_service.Service
nodeService: node_service.Service
networkConnectionService: network_connection_service.Service

# Forward declaration
proc resetOwnedCollectibles*(self: Controller, chainId: int, address: string)

proc newController*(
delegate: io_interface.AccessInterface,
events: EventEmitter,
collectibleService: collectible_service.Service,
walletAccountService: wallet_account_service.Service,
networkService: network_service.Service
networkService: network_service.Service,
nodeService: node_service.Service,
networkConnectionService: network_connection_service.Service
): Controller =
result = Controller()
result.delegate = delegate
result.events = events
result.collectibleService = collectibleService
result.walletAccountService = walletAccountService
result.networkService = networkService
result.nodeService = nodeService
result.networkConnectionService = networkConnectionService

proc delete*(self: Controller) =
discard
Expand All @@ -37,6 +47,8 @@ proc refreshCollectibles(self: Controller, chainId: int, address: string) =
self.delegate.setCollectibles(chainId, address, data)
else:
self.delegate.appendCollectibles(chainId, address, data)
if not self.nodeService.isConnected() or not self.networkConnectionService.checkIfConnected(COLLECTIBLES):
self.delegate.noConnectionToOpenSea()

proc init*(self: Controller) =
self.events.on(SIGNAL_OWNED_COLLECTIBLES_RESET) do(e:Args):
Expand All @@ -55,8 +67,17 @@ proc init*(self: Controller) =
let args = RetryCollectibleArgs(e)
let chainId = self.networkService.getNetworkForCollectibles().chainId
for address in args.addresses:
self.resetOwnedCollectibles(chainId, address)
self.refreshCollectibles(chainId, address)

self.events.on(SIGNAL_NETWORK_DISCONNECTED) do(e: Args):
self.delegate.noConnectionToOpenSea()

self.events.on(SIGNAL_CONNECTION_UPDATE) do(e:Args):
let args = NetworkConnectionsArgs(e)
if args.website == COLLECTIBLES and args.completelyDown:
self.delegate.noConnectionToOpenSea()

proc getWalletAccount*(self: Controller, accountIndex: int): wallet_account_service.WalletAccountDto =
return self.walletAccountService.getWalletAccount(accountIndex)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ method collectiblesModuleDidLoad*(self: AccessInterface) {.base.} =

method currentCollectibleModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

method noConnectionToOpenSea*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,8 @@ QtObject:
self.items = concat(self.items, items)
self.endInsertRows()
self.countChanged()

# in case loading is still going on and no items are present, show loading items when there is no connection to opensea possible
proc noConnectionToOpenSea*(self: Model) =
if self.items.len == 0:
self.setIsFetching(true)
12 changes: 9 additions & 3 deletions src/app/modules/main/wallet_section/collectibles/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import ../io_interface as delegate_interface
import ../../../../../app_service/service/collectible/service as collectible_service
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
import ../../../../../app_service/service/network/service as network_service
import ../../../../../app_service/service/node/service as node_service
import ../../../../../app_service/service/network_connection/service as network_connection_service

import ./current_collectible/module as current_collectible_module

Expand All @@ -34,12 +36,14 @@ proc newModule*(
events: EventEmitter,
collectibleService: collectible_service.Service,
walletAccountService: wallet_account_service.Service,
networkService: network_service.Service
networkService: network_service.Service,
nodeService: node_service.Service,
networkConnectionService: network_connection_service.Service
): Module =
result = Module()
result.delegate = delegate
result.view = newView(result)
result.controller = newController(result, events, collectibleService, walletAccountService, networkService)
result.controller = newController(result, events, collectibleService, walletAccountService, networkService, nodeService, networkConnectionService)
result.moduleLoaded = false
result.currentCollectibleModule = currentCollectibleModule.newModule(result, collectibleService)

Expand Down Expand Up @@ -109,7 +113,6 @@ method setCollectibles*(self: Module, chainId: int, address: string, data: Colle
self.view.setCollectibles(newCollectibles)
self.view.setAllLoaded(data.allLoaded)


method appendCollectibles*(self: Module, chainId: int, address: string, data: CollectiblesData) =
if self.chainId == chainId and self.address == address:
self.view.setIsFetching(data.isFetching)
Expand All @@ -122,3 +125,6 @@ method appendCollectibles*(self: Module, chainId: int, address: string, data: Co

self.view.appendCollectibles(newCollectibles)
self.view.setAllLoaded(data.allLoaded)

method noConnectionToOpenSea*(self: Module) =
self.view.noConnectionToOpenSea()
3 changes: 3 additions & 0 deletions src/app/modules/main/wallet_section/collectibles/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ QtObject:

proc appendCollectibles*(self: View, collectibles: seq[Item]) =
self.model.appendItems(collectibles)

proc noConnectionToOpenSea*(self: View) =
self.model.noConnectionToOpenSea()
10 changes: 8 additions & 2 deletions src/app/modules/main/wallet_section/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import ../../../../app_service/service/settings/service as settings_service
import ../../../../app_service/service/saved_address/service as saved_address_service
import ../../../../app_service/service/network/service as network_service
import ../../../../app_service/service/accounts/service as accounts_service
import ../../../../app_service/service/node/service as node_service
import ../../../../app_service/service/network_connection/service as network_connection_service

import io_interface
export io_interface
Expand Down Expand Up @@ -57,7 +59,9 @@ proc newModule*(
savedAddressService: saved_address_service.Service,
networkService: network_service.Service,
accountsService: accounts_service.Service,
keycardService: keycard_service.Service
keycardService: keycard_service.Service,
nodeService: node_service.Service,
networkConnectionService: network_connection_service.Service
): Module =
result = Module()
result.delegate = delegate
Expand All @@ -68,7 +72,7 @@ proc newModule*(

result.accountsModule = accounts_module.newModule(result, events, keycardService, walletAccountService, accountsService, networkService, tokenService, currencyService)
result.allTokensModule = all_tokens_module.newModule(result, events, tokenService, walletAccountService)
result.collectiblesModule = collectibles_module.newModule(result, events, collectibleService, walletAccountService, networkService)
result.collectiblesModule = collectibles_module.newModule(result, events, collectibleService, walletAccountService, networkService, nodeService, networkConnectionService)
result.currentAccountModule = current_account_module.newModule(result, events, walletAccountService, networkService, tokenService, currencyService)
result.transactionsModule = transactions_module.newModule(result, events, transactionService, walletAccountService, networkService, currencyService)
result.savedAddressesModule = saved_addresses_module.newModule(result, events, savedAddressService)
Expand Down Expand Up @@ -121,6 +125,8 @@ method load*(self: Module) =
self.events.on(SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT) do(e:Args):
self.setTotalCurrencyBalance()
self.view.setTokensLoading(false)
self.events.on(SIGNAL_WALLET_ACCOUNT_TOKENS_BEING_FETCHED) do(e:Args):
self.view.setTokensLoading(true)
self.events.on(SIGNAL_CURRENCY_FORMATS_UPDATED) do(e:Args):
self.setTotalCurrencyBalance()

Expand Down
2 changes: 1 addition & 1 deletion src/app_service/service/collectible/async_tasks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const fetchOwnedCollectiblesTaskArg: Task = proc(argEncoded: string) {.gcsafe, n
"chainId": arg.chainId,
"address": arg.address,
"cursor": arg.cursor,
"collectibles": ""
"collectibles": {"assets":nil,"next":"","previous":""}
}
try:
let response = collectibles.getOpenseaAssetsByOwnerWithCursor(arg.chainId, arg.address, arg.cursor, arg.limit)
Expand Down
6 changes: 3 additions & 3 deletions src/app_service/service/collectible/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ QtObject:

# needs to be re-written once cache for colletibles works
proc areCollectionsLoaded*(self: Service): bool =
for chainId, adressesData in self.ownershipData:
for address, collectionsData in adressesData:
if collectionsData.allLoaded:
for chainId, adressesData in self.accountsOwnershipData:
for address, ownershipData in adressesData:
if ownershipData.data.allLoaded:
return true
return false

Expand Down
Loading

0 comments on commit 4fee741

Please sign in to comment.