-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(@desktop/wallet): Wallet: explore streamlining "all tokens mode…
…l" spread across different sections closes #12424
- Loading branch information
1 parent
466b57a
commit fb4fe9a
Showing
25 changed files
with
1,215 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/app/modules/main/wallet_section/new_tokens/controller.nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
116
src/app/modules/main/wallet_section/new_tokens/flat_tokens_model.nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
45
src/app/modules/main/wallet_section/new_tokens/io_interface.nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
Oops, something went wrong.