Skip to content

Commit

Permalink
chore(@desktop/wallet): Wallet: explore streamlining "all tokens mode…
Browse files Browse the repository at this point in the history
…l" spread across different sections

closes #12424
  • Loading branch information
Khushboo-dev-cpp committed Oct 25, 2023
1 parent 466b57a commit fb4fe9a
Show file tree
Hide file tree
Showing 25 changed files with 1,215 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/app/boot/app_controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import ../../app_service/service/mailservers/service as mailservers_service
import ../../app_service/service/gif/service as gif_service
import ../../app_service/service/ens/service as ens_service
import ../../app_service/service/community_tokens/service as tokens_service
import ../../app_service/service/new_token/service as new_tokens_service
import ../../app_service/service/network_connection/service as network_connection_service
import ../../app_service/service/shared_urls/service as shared_urls_service

Expand Down Expand Up @@ -97,6 +98,7 @@ type
gifService: gif_service.Service
ensService: ens_service.Service
tokensService: tokens_service.Service
newTokensService: new_tokens_service.Service
networkConnectionService: network_connection_service.Service
sharedUrlsService: shared_urls_service.Service

Expand Down Expand Up @@ -226,6 +228,7 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController =
result.networkService, result.tokenService)
result.tokensService = tokens_service.newService(statusFoundation.events, statusFoundation.threadpool,
result.transactionService, result.tokenService, result.settingsService, result.walletAccountService)
result.newTokensService = new_tokens_service.newService(statusFoundation.events, statusFoundation.threadpool, result.networkService)
result.providerService = provider_service.newService(statusFoundation.events, statusFoundation.threadpool, result.ensService)
result.networkConnectionService = network_connection_service.newService(statusFoundation.events, result.walletAccountService, result.networkService, result.nodeService)
result.sharedUrlsService = shared_urls_service.newService(statusFoundation.events, statusFoundation.threadpool)
Expand Down Expand Up @@ -277,7 +280,8 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController =
result.generalService,
result.keycardService,
result.networkConnectionService,
result.sharedUrlsService
result.sharedUrlsService,
result.newTokensService
)

# Do connections
Expand Down Expand Up @@ -311,6 +315,7 @@ proc delete*(self: AppController) =
self.communityService.delete
self.currencyService.delete
self.tokenService.delete
self.newTokensService.delete
self.transactionService.delete
self.walletAccountService.delete
self.aboutService.delete
Expand Down Expand Up @@ -434,6 +439,7 @@ proc load(self: AppController) =

self.networkService.init()
self.tokenService.init()
self.newTokensService.init()
self.currencyService.init()
self.walletAccountService.init()

Expand Down
7 changes: 5 additions & 2 deletions src/app/modules/main/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import ../../../app_service/service/chat/service as chat_service
import ../../../app_service/service/community/service as community_service
import ../../../app_service/service/message/service as message_service
import ../../../app_service/service/token/service as token_service
import ../../../app_service/service/new_token/service as new_token_service
import ../../../app_service/service/currency/service as currency_service
import ../../../app_service/service/transaction/service as transaction_service
import ../../../app_service/service/wallet_account/service as wallet_account_service
Expand Down Expand Up @@ -153,7 +154,8 @@ proc newModule*[T](
generalService: general_service.Service,
keycardService: keycard_service.Service,
networkConnectionService: network_connection_service.Service,
sharedUrlsService: urls_service.Service
sharedUrlsService: urls_service.Service,
newTokensService: new_token_service.Service
): Module[T] =
result = Module[T]()
result.delegate = delegate
Expand Down Expand Up @@ -198,7 +200,8 @@ proc newModule*[T](
result, events, tokenService, currencyService,
transactionService, walletAccountService,
settingsService, savedAddressService, networkService, accountsService,
keycardService, nodeService, networkConnectionService, devicesService
keycardService, nodeService, networkConnectionService, devicesService,
newTokensService
)
result.browserSectionModule = browser_section_module.newModule(
result, events, bookmarkService, settingsService, networkService,
Expand Down
3 changes: 3 additions & 0 deletions src/app/modules/main/wallet_section/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ method sendModuleDidLoad*(self: AccessInterface) {.base.} =
method overviewModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

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

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

Expand Down
18 changes: 17 additions & 1 deletion src/app/modules/main/wallet_section/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ../io_interface as delegate_interface

import ./accounts/module as accounts_module
import ./all_tokens/module as all_tokens_module
import ./new_tokens/module as new_tokens_module
import ./assets/module as assets_module
import ./saved_addresses/module as saved_addresses_module
import ./buy_sell_crypto/module as buy_sell_crypto_module
Expand All @@ -23,6 +24,7 @@ import app/modules/shared_modules/add_account/module as add_account_module
import app/modules/shared_modules/keypair_import/module as keypair_import_module
import app_service/service/keycard/service as keycard_service
import app_service/service/token/service as token_service
import app_service/service/new_token/service as new_token_service
import app_service/service/currency/service as currency_service
import app_service/service/transaction/service as transaction_service
import app_service/service/wallet_account/service as wallet_account_service
Expand Down Expand Up @@ -68,6 +70,8 @@ type
buySellCryptoModule: buy_sell_crypto_module.AccessInterface
overviewModule: overview_module.AccessInterface
networksModule: networks_module.AccessInterface
newTokensModule: new_tokens_module.AccessInterface

networksService: network_service.Service
transactionService: transaction_service.Service
keycardService: keycard_service.Service
Expand Down Expand Up @@ -99,7 +103,8 @@ proc newModule*(
keycardService: keycard_service.Service,
nodeService: node_service.Service,
networkConnectionService: network_connection_service.Service,
devicesService: devices_service.Service
devicesService: devices_service.Service,
newTokenService: new_token_service.Service,
): Module =
result = Module()
result.delegate = delegate
Expand All @@ -121,6 +126,8 @@ proc newModule*(
result.buySellCryptoModule = buy_sell_crypto_module.newModule(result, events, transactionService)
result.overviewModule = overview_module.newModule(result, events, walletAccountService, currencyService)
result.networksModule = networks_module.newModule(result, events, networkService, walletAccountService, settingsService)
result.newTokensModule = new_tokens_module.newModule(result, events, newTokenService)

result.networksService = networkService

result.transactionService = transactionService
Expand Down Expand Up @@ -152,6 +159,7 @@ method delete*(self: Module) =
self.tmpActivityController.delete
self.collectiblesController.delete
self.collectibleDetailsController.delete
self.newTokensModule.delete

if not self.addAccountModule.isNil:
self.addAccountModule.delete
Expand Down Expand Up @@ -268,6 +276,7 @@ method load*(self: Module) =
self.overviewModule.load()
self.sendModule.load()
self.networksModule.load()
self.newTokensModule.load()

method isLoaded*(self: Module): bool =
return self.moduleLoaded
Expand Down Expand Up @@ -297,6 +306,10 @@ proc checkIfModuleDidLoad(self: Module) =
if(not self.networksModule.isLoaded()):
return


if(not self.newTokensModule.isLoaded()):
return

let signingPhrase = self.controller.getSigningPhrase()
let mnemonicBackedUp = self.controller.isMnemonicBackedUp()
self.view.setData(signingPhrase, mnemonicBackedUp)
Expand Down Expand Up @@ -339,6 +352,9 @@ method sendModuleDidLoad*(self: Module) =
method networksModuleDidLoad*(self: Module) =
self.checkIfModuleDidLoad()

method newTokensModuleDidLoad*(self: Module) =
self.checkIfModuleDidLoad()

method destroyAddAccountPopup*(self: Module) =
if self.addAccountModule.isNil:
return
Expand Down
32 changes: 32 additions & 0 deletions src/app/modules/main/wallet_section/new_tokens/controller.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import app_service/service/new_token/service as token_service
import app_service/service/new_token/service_items

import ./io_interface

type
Controller* = ref object of RootObj
delegate: io_interface.AccessInterface
tokenService: token_service.Service

proc newController*(
delegate: io_interface.AccessInterface,
tokenService: token_service.Service,
): Controller =
result = Controller()
result.delegate = delegate
result.tokenService = tokenService

proc delete*(self: Controller) =
discard

proc init*(self: Controller) =
discard

proc getSourcesOfTokensList*(self: Controller): seq[SupportedSourcesItem] =
return self.tokenService.getSourcesOfTokensList()

proc getFlatTokensList*(self: Controller): seq[TokenItem] =
return self.tokenService.getFlatTokensList()

proc getTokenBySymbolList*(self: Controller): seq[TokenBySymbolItem] =
return self.tokenService.getTokenBySymbolList()
116 changes: 116 additions & 0 deletions src/app/modules/main/wallet_section/new_tokens/flat_tokens_model.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import NimQml, Tables, strutils

import app/core/eventemitter
import ./io_interface

type
ModelRole {.pure.} = enum
Key = UserRole + 1
Name
Symbol
# uniswap/status/custom seq[string]
Sources
ChainId
Address
Decimals
Image
# Native, Erc20, Erc721
Type
# only be valid if source is custom
CommunityId
# everything below should be lazy loaded
Description
# properties below this are optional and may not exist in case of community minted assets
# built from chainId and address using networks service
WebsiteUrl
MarketValues

QtObject:
type FlatTokensModel* = ref object of QAbstractListModel
delegate: io_interface.FlatTokenModelDataSource
events: EventEmitter

proc setup(self: FlatTokensModel) =
self.QAbstractListModel.setup

proc delete(self: FlatTokensModel) =
self.QAbstractListModel.delete

proc newFlatTokensModel*(delegate: io_interface.FlatTokenModelDataSource, events: EventEmitter): FlatTokensModel =
new(result, delete)
result.setup
result.delegate = delegate
result.events = events

proc load*(self: FlatTokensModel) =
# events from module informing of updated in model from service side
self.events.on(SIGNAL_MODULE_TOKEN_LIST_ABOUT_TO_BE_UPDATED) do(e: Args):
self.beginResetModel()

self.events.on(SIGNAL_MODULE_TOKEN_LIST_UPDATED) do(e: Args):
self.endResetModel()

method rowCount(self: FlatTokensModel, index: QModelIndex = nil): int =
return self.delegate.getFlatTokensList().len

proc countChanged(self: FlatTokensModel) {.signal.}
proc getCount(self: FlatTokensModel): int {.slot.} =
return self.rowCount()
QtProperty[int] count:
read = getCount
notify = countChanged

method roleNames(self: FlatTokensModel): Table[int, string] =
{
ModelRole.Key.int:"key",
ModelRole.Name.int:"name",
ModelRole.Symbol.int:"symbol",
ModelRole.Sources.int:"sources",
ModelRole.ChainId.int:"chainId",
ModelRole.Address.int:"address",
ModelRole.Decimals.int:"decimals",
ModelRole.Image.int:"image",
ModelRole.Type.int:"type",
ModelRole.CommunityId.int:"communityId",
ModelRole.Description.int:"description",
ModelRole.WebsiteUrl.int:"websiteUrl",
ModelRole.MarketValues.int:"marketValues",
}.toTable

method data(self: FlatTokensModel, index: QModelIndex, role: int): QVariant =
if not index.isValid:
return
if index.row < 0 or index.row >= self.rowCount():
return
# the only way to read items from service is by this single method getFlatTokensList
let item = self.delegate.getFlatTokensList()[index.row]
let enumRole = role.ModelRole
case enumRole:
of ModelRole.Key:
result = newQVariant(item.key)
of ModelRole.Name:
result = newQVariant(item.name)
of ModelRole.Symbol:
result = newQVariant(item.symbol)
# Todo need to expose a model here again
of ModelRole.Sources:
result = newQVariant(item.sources.join(";"))
of ModelRole.ChainId:
result = newQVariant(item.chainId)
of ModelRole.Address:
result = newQVariant(item.address)
of ModelRole.Decimals:
result = newQVariant(item.decimals)
of ModelRole.Image:
result = newQVariant(item.image)
of ModelRole.Type:
result = newQVariant(ord(item.tokenType))
of ModelRole.CommunityId:
result = newQVariant(item.communityId)
# ToDo fetching of market values not done yet
of ModelRole.Description:
result = newQVariant("")
of ModelRole.WebsiteUrl:
result = newQVariant("")
of ModelRole.MarketValues:
result = newQVariant("")
45 changes: 45 additions & 0 deletions src/app/modules/main/wallet_section/new_tokens/io_interface.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import app_service/service/new_token/service_items

const SIGNAL_MODULE_TOKEN_LIST_UPDATED* = "signalModuleTokenListUpdated"
const SIGNAL_MODULE_TOKEN_LIST_ABOUT_TO_BE_UPDATED* = "signalModuleTokenListAboutToBeUpdated"

type
SourcesOfTokensModelDataSource* = tuple[
getSourcesOfTokensList: proc(): seq[SupportedSourcesItem]
]
type
FlatTokenModelDataSource* = tuple[
getFlatTokensList: proc(): seq[TokenItem]
]
type
TokenBySymbolModelDataSource* = tuple[
getTokenBySymbolList: proc(): seq[TokenBySymbolItem]
]

type
AccessInterface* {.pure inheritable.} = ref object of RootObj
## Abstract class for any input/interaction with this module.

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

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

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

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

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

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

# View Delegate Interface
# Delegate for the view must be declared here due to use of QtObject and multi
# inheritance, which is not well supported in Nim.
method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
Loading

0 comments on commit fb4fe9a

Please sign in to comment.