chore(wallet): remove collectibles service
This commit is contained in:
parent
dc75c120df
commit
44cf2b6faa
|
@ -12,7 +12,6 @@ import ../../app_service/service/message/service as message_service
|
|||
import ../../app_service/service/token/service as token_service
|
||||
import ../../app_service/service/currency/service as currency_service
|
||||
import ../../app_service/service/transaction/service as transaction_service
|
||||
import ../../app_service/service/collectible/service as collectible_service
|
||||
import ../../app_service/service/wallet_account/service as wallet_account_service
|
||||
import ../../app_service/service/bookmarks/service as bookmark_service
|
||||
import ../../app_service/service/dapp_permissions/service as dapp_permissions_service
|
||||
|
@ -77,7 +76,6 @@ type
|
|||
tokenService: token_service.Service
|
||||
currencyService: currency_service.Service
|
||||
transactionService: transaction_service.Service
|
||||
collectibleService: collectible_service.Service
|
||||
walletAccountService: wallet_account_service.Service
|
||||
bookmarkService: bookmark_service.Service
|
||||
dappPermissionsService: dapp_permissions_service.Service
|
||||
|
@ -182,7 +180,6 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController =
|
|||
result.currencyService = currency_service.newService(
|
||||
statusFoundation.events, statusFoundation.threadpool, result.tokenService, result.settingsService
|
||||
)
|
||||
result.collectibleService = collectible_service.newService(statusFoundation.events, statusFoundation.threadpool, result.networkService)
|
||||
result.walletAccountService = wallet_account_service.newService(
|
||||
statusFoundation.events, statusFoundation.threadpool, result.settingsService, result.accountsService,
|
||||
result.tokenService, result.networkService, result.currencyService
|
||||
|
@ -254,7 +251,6 @@ proc newAppController*(statusFoundation: StatusFoundation): AppController =
|
|||
result.tokenService,
|
||||
result.currencyService,
|
||||
result.transactionService,
|
||||
result.collectibleService,
|
||||
result.walletAccountService,
|
||||
result.bookmarkService,
|
||||
result.profileService,
|
||||
|
@ -315,7 +311,6 @@ proc delete*(self: AppController) =
|
|||
self.currencyService.delete
|
||||
self.tokenService.delete
|
||||
self.transactionService.delete
|
||||
self.collectibleService.delete
|
||||
self.walletAccountService.delete
|
||||
self.aboutService.delete
|
||||
self.networkService.delete
|
||||
|
@ -440,7 +435,6 @@ proc load(self: AppController) =
|
|||
self.tokenService.init()
|
||||
self.currencyService.init()
|
||||
self.walletAccountService.init()
|
||||
self.collectibleService.init()
|
||||
|
||||
# Apply runtime log level settings
|
||||
if not existsEnv("LOG_LEVEL"):
|
||||
|
|
|
@ -13,9 +13,9 @@ import ../../../../app_service/service/mailservers/service as mailservers_servic
|
|||
import ../../../../app_service/service/wallet_account/service as wallet_account_service
|
||||
import ../../../../app_service/service/token/service as token_service
|
||||
import ../../../../app_service/service/community_tokens/service as community_tokens_service
|
||||
import ../../../../app_service/service/collectible/service as collectible_service
|
||||
import ../../../../app_service/service/visual_identity/service as procs_from_visual_identity_service
|
||||
import ../../shared_modules/keycard_popup/io_interface as keycard_shared_module
|
||||
import backend/collectibles as backend_collectibles
|
||||
|
||||
import ../../../core/signals/types
|
||||
import ../../../global/app_signals
|
||||
|
@ -42,7 +42,6 @@ type
|
|||
mailserversService: mailservers_service.Service
|
||||
walletAccountService: wallet_account_service.Service
|
||||
tokenService: token_service.Service
|
||||
collectibleService: collectible_service.Service
|
||||
communityTokensService: community_tokens_service.Service
|
||||
tmpAuthenticationForJoinInProgress: bool
|
||||
tmpAuthenticationForEditSharedAddresses: bool
|
||||
|
@ -58,7 +57,6 @@ proc newController*(delegate: io_interface.AccessInterface, sectionId: string, i
|
|||
mailserversService: mailservers_service.Service,
|
||||
walletAccountService: wallet_account_service.Service,
|
||||
tokenService: token_service.Service,
|
||||
collectibleService: collectible_service.Service,
|
||||
communityTokensService: community_tokens_service.Service): Controller =
|
||||
result = Controller()
|
||||
result.delegate = delegate
|
||||
|
@ -76,7 +74,6 @@ proc newController*(delegate: io_interface.AccessInterface, sectionId: string, i
|
|||
result.mailserversService = mailserversService
|
||||
result.walletAccountService = walletAccountService
|
||||
result.tokenService = tokenService
|
||||
result.collectibleService = collectibleService
|
||||
result.communityTokensService = communityTokensService
|
||||
result.tmpAuthenticationForJoinInProgress = false
|
||||
result.tmpAuthenticationForEditSharedAddresses = false
|
||||
|
@ -361,8 +358,11 @@ proc init*(self: Controller) =
|
|||
if args.communityId == self.sectionId:
|
||||
self.delegate.onCommunityCheckAllChannelsPermissionsResponse(args.checkAllChannelsPermissionsResponse)
|
||||
|
||||
self.events.on(SIGNAL_OWNED_COLLECTIBLES_UPDATE_FINISHED) do(e: Args):
|
||||
self.asyncCheckPermissions()
|
||||
self.events.on(SignalType.Wallet.event, proc(e: Args) =
|
||||
var data = WalletSignal(e)
|
||||
if data.eventType == backend_collectibles.eventCollectiblesOwnershipUpdateFinished:
|
||||
self.asyncCheckPermissions()
|
||||
)
|
||||
|
||||
self.events.on(SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT) do(e: Args):
|
||||
self.asyncCheckPermissions()
|
||||
|
@ -712,18 +712,6 @@ proc deleteCommunityTokenPermission*(self: Controller, communityId: string, perm
|
|||
proc allAccountsTokenBalance*(self: Controller, symbol: string): float64 =
|
||||
return self.walletAccountService.allAccountsTokenBalance(symbol)
|
||||
|
||||
proc ownsCollectible*(self: Controller, chainId: int, contractAddress: string, tokenIds: seq[string]): bool =
|
||||
let addresses = self.walletAccountService.getWalletAccounts().filter(a => a.walletType != WalletTypeWatch).map(a => a.address)
|
||||
|
||||
for address in addresses:
|
||||
let data = self.collectibleService.getOwnedCollectibles(chainId, @[address])
|
||||
|
||||
for collectible in data[0].collectibles:
|
||||
if collectible.id.contractAddress == contractAddress.toLowerAscii:
|
||||
return true
|
||||
|
||||
return false
|
||||
|
||||
proc getTokenList*(self: Controller): seq[TokenDto] =
|
||||
return self.tokenService.getTokenList()
|
||||
|
||||
|
|
|
@ -32,7 +32,6 @@ import ../../../../app_service/service/mailservers/service as mailservers_servic
|
|||
import ../../../../app_service/service/gif/service as gif_service
|
||||
import ../../../../app_service/service/wallet_account/service as wallet_account_service
|
||||
import ../../../../app_service/service/token/service as token_service
|
||||
import ../../../../app_service/service/collectible/service as collectible_service
|
||||
import ../../../../app_service/service/community_tokens/service as community_tokens_service
|
||||
import ../../../../app_service/service/visual_identity/service as visual_identity
|
||||
import ../../../../app_service/service/contacts/dto/contacts as contacts_dto
|
||||
|
@ -102,13 +101,12 @@ proc newModule*(
|
|||
mailserversService: mailservers_service.Service,
|
||||
walletAccountService: wallet_account_service.Service,
|
||||
tokenService: token_service.Service,
|
||||
collectibleService: collectible_service.Service,
|
||||
communityTokensService: community_tokens_service.Service,
|
||||
): Module =
|
||||
result = Module()
|
||||
result.delegate = delegate
|
||||
result.controller = controller.newController(result, sectionId, isCommunity, events, settingsService, nodeConfigurationService,
|
||||
contactService, chatService, communityService, messageService, gifService, mailserversService, walletAccountService, tokenService, collectibleService, communityTokensService)
|
||||
contactService, chatService, communityService, messageService, gifService, mailserversService, walletAccountService, tokenService, communityTokensService)
|
||||
result.view = view.newView(result)
|
||||
result.viewVariant = newQVariant(result.view)
|
||||
result.moduleLoaded = false
|
||||
|
|
|
@ -11,7 +11,7 @@ import ../../../../app_service/service/network/service as networks_service
|
|||
import ../../../../app_service/service/community_tokens/service as community_tokens_service
|
||||
import ../../../../app_service/service/token/service as token_service
|
||||
import ../../../../app_service/service/wallet_account/service as wallet_account_service
|
||||
import ../../../../app_service/service/collectible/service as collectible_service
|
||||
import backend/collectibles as backend_collectibles
|
||||
|
||||
type
|
||||
Controller* = ref object of RootObj
|
||||
|
@ -142,8 +142,11 @@ proc init*(self: Controller) =
|
|||
let args = CommunityTokenMetadataArgs(e)
|
||||
self.delegate.onCommunityTokenMetadataAdded(args.communityId, args.tokenMetadata)
|
||||
|
||||
self.events.on(SIGNAL_OWNED_COLLECTIBLES_UPDATE_FINISHED) do(e: Args):
|
||||
self.delegate.onOwnedCollectiblesUpdated()
|
||||
self.events.on(SignalType.Wallet.event, proc(e: Args) =
|
||||
var data = WalletSignal(e)
|
||||
if data.eventType == backend_collectibles.eventCollectiblesOwnershipUpdateFinished:
|
||||
self.delegate.onOwnedCollectiblesUpdated()
|
||||
)
|
||||
|
||||
self.events.on(SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT) do(e: Args):
|
||||
self.delegate.onWalletAccountTokensRebuilt()
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import strformat, sequtils, stint
|
||||
import ../../../../../../app_service/service/community_tokens/dto/community_token
|
||||
import ../../../../../../app_service/service/collectible/dto
|
||||
import ../../../../../../app_service/service/network/dto
|
||||
import ../../../../../../app_service/common/types
|
||||
from backend/collectibles_types import CollectibleOwner
|
||||
|
||||
import token_owners_model
|
||||
import token_owners_item
|
||||
|
|
|
@ -3,9 +3,9 @@ import token_item
|
|||
import token_owners_item
|
||||
import token_owners_model
|
||||
import ../../../../../../app_service/service/community_tokens/dto/community_token
|
||||
import ../../../../../../app_service/service/collectible/dto
|
||||
import ../../../../../../app_service/common/utils
|
||||
import ../../../../../../app_service/common/types
|
||||
from backend/collectibles_types import CollectibleOwner
|
||||
|
||||
type
|
||||
ModelRole {.pure.} = enum
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import strformat, stint
|
||||
import ../../../../../../app_service/service/collectible/dto
|
||||
import backend/collectibles_types
|
||||
|
||||
type
|
||||
TokenOwnersItem* = object
|
||||
|
|
|
@ -21,7 +21,7 @@ import ../../../app_service/service/community_tokens/service as community_tokens
|
|||
import ../../../app_service/service/wallet_account/service as wallet_account_service
|
||||
import ../../../app_service/service/token/service as token_service
|
||||
import ../../../app_service/service/network/service as networks_service
|
||||
import ../../../app_service/service/collectible/service as collectible_service
|
||||
from backend/collectibles_types import CollectibleOwner
|
||||
|
||||
import io_interface
|
||||
import ../shared_modules/keycard_popup/io_interface as keycard_shared_module
|
||||
|
@ -53,7 +53,6 @@ type
|
|||
walletAccountService: wallet_account_service.Service
|
||||
tokenService: token_service.Service
|
||||
networksService: networks_service.Service
|
||||
collectibleService: collectible_service.Service
|
||||
|
||||
# Forward declaration
|
||||
proc setActiveSection*(self: Controller, sectionId: string, skipSavingInSettings: bool = false)
|
||||
|
@ -75,8 +74,7 @@ proc newController*(delegate: io_interface.AccessInterface,
|
|||
communityTokensService: community_tokens_service.Service,
|
||||
walletAccountService: wallet_account_service.Service,
|
||||
tokenService: token_service.Service,
|
||||
networksService: networks_service.Service,
|
||||
collectibleService: collectible_service.Service
|
||||
networksService: networks_service.Service
|
||||
):
|
||||
Controller =
|
||||
result = Controller()
|
||||
|
@ -97,7 +95,6 @@ proc newController*(delegate: io_interface.AccessInterface,
|
|||
result.walletAccountService = walletAccountService
|
||||
result.tokenService = tokenService
|
||||
result.networksService = networksService
|
||||
result.collectibleService = collectibleService
|
||||
|
||||
proc delete*(self: Controller) =
|
||||
discard
|
||||
|
@ -118,7 +115,6 @@ proc init*(self: Controller) =
|
|||
self.mailserversService,
|
||||
self.walletAccountService,
|
||||
self.tokenService,
|
||||
self.collectibleService,
|
||||
self.communityTokensService
|
||||
)
|
||||
|
||||
|
@ -135,7 +131,6 @@ proc init*(self: Controller) =
|
|||
self.mailserversService,
|
||||
self.walletAccountService,
|
||||
self.tokenService,
|
||||
self.collectibleService,
|
||||
self.communityTokensService
|
||||
)
|
||||
|
||||
|
@ -171,7 +166,6 @@ proc init*(self: Controller) =
|
|||
self.mailserversService,
|
||||
self.walletAccountService,
|
||||
self.tokenService,
|
||||
self.collectibleService,
|
||||
self.communityTokensService,
|
||||
setActive = args.fromUserAction
|
||||
)
|
||||
|
@ -191,7 +185,6 @@ proc init*(self: Controller) =
|
|||
self.mailserversService,
|
||||
self.walletAccountService,
|
||||
self.tokenService,
|
||||
self.collectibleService,
|
||||
self.communityTokensService,
|
||||
setActive = args.fromUserAction
|
||||
)
|
||||
|
@ -215,7 +208,6 @@ proc init*(self: Controller) =
|
|||
self.mailserversService,
|
||||
self.walletAccountService,
|
||||
self.tokenService,
|
||||
self.collectibleService,
|
||||
self.communityTokensService,
|
||||
setActive = true
|
||||
)
|
||||
|
@ -237,7 +229,6 @@ proc init*(self: Controller) =
|
|||
self.mailserversService,
|
||||
self.walletAccountService,
|
||||
self.tokenService,
|
||||
self.collectibleService,
|
||||
self.communityTokensService,
|
||||
setActive = false
|
||||
)
|
||||
|
|
|
@ -11,9 +11,9 @@ import ../../../app_service/service/mailservers/service as mailservers_service
|
|||
import ../../../app_service/service/community_tokens/service as community_token_service
|
||||
import ../../../app_service/service/wallet_account/service as wallet_account_service
|
||||
import ../../../app_service/service/token/service as token_service
|
||||
import ../../../app_service/service/collectible/service as collectible_service
|
||||
import ../../../app_service/service/community_tokens/service as community_tokens_service
|
||||
from ../../../app_service/common/types import StatusType, ContractTransactionStatus
|
||||
from backend/collectibles_types import CollectibleOwner
|
||||
|
||||
import ../../global/app_signals
|
||||
import ../../core/eventemitter
|
||||
|
@ -87,7 +87,6 @@ method onChannelGroupsLoaded*(
|
|||
mailserversService: mailservers_service.Service,
|
||||
walletAccountService: wallet_account_service.Service,
|
||||
tokenService: token_service.Service,
|
||||
collectibleService: collectible_service.Service,
|
||||
communityTokensService: community_tokens_service.Service)
|
||||
{.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
@ -105,7 +104,6 @@ method onCommunityDataLoaded*(
|
|||
mailserversService: mailservers_service.Service,
|
||||
walletAccountService: wallet_account_service.Service,
|
||||
tokenService: token_service.Service,
|
||||
collectibleService: collectible_service.Service,
|
||||
communityTokensService: community_tokens_service.Service)
|
||||
{.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
@ -153,7 +151,6 @@ method communityJoined*(self: AccessInterface, community: CommunityDto, events:
|
|||
mailserversService: mailservers_service.Service,
|
||||
walletAccountService: wallet_account_service.Service,
|
||||
tokenService: token_service.Service,
|
||||
collectibleService: collectible_service.Service,
|
||||
communityTokensService: community_tokens_service.Service,
|
||||
setActive: bool = false,) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
|
|
@ -28,6 +28,7 @@ import network_connection/module as network_connection_module
|
|||
import shared_urls/module as shared_urls_module
|
||||
|
||||
import ../../../app_service/service/contacts/dto/contacts
|
||||
from backend/collectibles_types import CollectibleOwner
|
||||
|
||||
import ../../../app_service/service/keychain/service as keychain_service
|
||||
import ../../../app_service/service/chat/service as chat_service
|
||||
|
@ -36,7 +37,6 @@ import ../../../app_service/service/message/service as message_service
|
|||
import ../../../app_service/service/token/service as token_service
|
||||
import ../../../app_service/service/currency/service as currency_service
|
||||
import ../../../app_service/service/transaction/service as transaction_service
|
||||
import ../../../app_service/service/collectible/service as collectible_service
|
||||
import ../../../app_service/service/wallet_account/service as wallet_account_service
|
||||
import ../../../app_service/service/bookmarks/service as bookmark_service
|
||||
import ../../../app_service/service/dapp_permissions/service as dapp_permissions_service
|
||||
|
@ -127,7 +127,6 @@ proc newModule*[T](
|
|||
tokenService: token_service.Service,
|
||||
currencyService: currency_service.Service,
|
||||
transactionService: transaction_service.Service,
|
||||
collectibleService: collectible_service.Service,
|
||||
walletAccountService: wallet_account_service.Service,
|
||||
bookmarkService: bookmark_service.Service,
|
||||
profileService: profile_service.Service,
|
||||
|
@ -176,7 +175,6 @@ proc newModule*[T](
|
|||
walletAccountService,
|
||||
tokenService,
|
||||
networkService,
|
||||
collectibleService
|
||||
)
|
||||
result.moduleLoaded = false
|
||||
result.chatsLoaded = false
|
||||
|
@ -196,7 +194,7 @@ proc newModule*[T](
|
|||
result.channelGroupModules = initOrderedTable[string, chat_section_module.AccessInterface]()
|
||||
result.walletSectionModule = wallet_section_module.newModule(
|
||||
result, events, tokenService, currencyService,
|
||||
transactionService, collectible_service, walletAccountService,
|
||||
transactionService, walletAccountService,
|
||||
settingsService, savedAddressService, networkService, accountsService,
|
||||
keycardService, nodeService, networkConnectionService
|
||||
)
|
||||
|
@ -567,7 +565,6 @@ method onChannelGroupsLoaded*[T](
|
|||
mailserversService: mailservers_service.Service,
|
||||
walletAccountService: wallet_account_service.Service,
|
||||
tokenService: token_service.Service,
|
||||
collectibleService: collectible_service.Service,
|
||||
communityTokensService: community_tokens_service.Service
|
||||
) =
|
||||
self.chatsLoaded = true
|
||||
|
@ -594,7 +591,6 @@ method onChannelGroupsLoaded*[T](
|
|||
mailserversService,
|
||||
walletAccountService,
|
||||
tokenService,
|
||||
collectibleService,
|
||||
communityTokensService
|
||||
)
|
||||
let channelGroupItem = self.createChannelGroupItem(channelGroup)
|
||||
|
@ -627,7 +623,6 @@ method onCommunityDataLoaded*[T](
|
|||
mailserversService: mailservers_service.Service,
|
||||
walletAccountService: wallet_account_service.Service,
|
||||
tokenService: token_service.Service,
|
||||
collectibleService: collectible_service.Service,
|
||||
communityTokensService: community_tokens_service.Service
|
||||
) =
|
||||
self.communityDataLoaded = true
|
||||
|
@ -647,7 +642,6 @@ method onCommunityDataLoaded*[T](
|
|||
mailserversService,
|
||||
walletAccountService,
|
||||
tokenService,
|
||||
collectibleService,
|
||||
communityTokensService
|
||||
)
|
||||
|
||||
|
@ -869,7 +863,6 @@ method communityJoined*[T](
|
|||
mailserversService: mailservers_service.Service,
|
||||
walletAccountService: wallet_account_service.Service,
|
||||
tokenService: token_service.Service,
|
||||
collectibleService: collectible_service.Service,
|
||||
communityTokensService: community_tokens_service.Service,
|
||||
setActive: bool = false,
|
||||
) =
|
||||
|
@ -891,7 +884,6 @@ method communityJoined*[T](
|
|||
mailserversService,
|
||||
walletAccountService,
|
||||
tokenService,
|
||||
collectibleService,
|
||||
communityTokensService
|
||||
)
|
||||
let channelGroup = community.toChannelGroupDto()
|
||||
|
|
|
@ -4,7 +4,6 @@ import ../../../../../app_service/service/wallet_account/service as wallet_accou
|
|||
import ../../../../../app_service/service/network/service as network_service
|
||||
import ../../../../../app_service/service/token/service as token_service
|
||||
import ../../../../../app_service/service/currency/service as currency_service
|
||||
import ../../../../../app_service/service/collectible/service as collectible_service
|
||||
|
||||
type
|
||||
Controller* = ref object of RootObj
|
||||
|
|
|
@ -7,7 +7,6 @@ import ../../../../../app_service/service/currency/service as currency_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/network_connection/service as network_connection
|
||||
import ../../../../../app_service/service/collectible/service as collectible_service
|
||||
import ../../../../../app_service/service/node/service as node_service
|
||||
import ../../../shared/wallet_utils
|
||||
import ../../../shared_models/currency_amount
|
||||
|
|
|
@ -25,7 +25,6 @@ import ../../../../app_service/service/keycard/service as keycard_service
|
|||
import ../../../../app_service/service/token/service as token_service
|
||||
import ../../../../app_service/service/currency/service as currency_service
|
||||
import ../../../../app_service/service/transaction/service as transaction_service
|
||||
import ../../../../app_service/service/collectible/service as collectible_service
|
||||
import ../../../../app_service/service/wallet_account/service as wallet_account_service
|
||||
import ../../../../app_service/service/settings/service as settings_service
|
||||
import ../../../../app_service/service/saved_address/service as saved_address_service
|
||||
|
@ -73,7 +72,6 @@ proc newModule*(
|
|||
tokenService: token_service.Service,
|
||||
currencyService: currency_service.Service,
|
||||
transactionService: transaction_service.Service,
|
||||
collectibleService: collectible_service.Service,
|
||||
walletAccountService: wallet_account_service.Service,
|
||||
settingsService: settings_service.Service,
|
||||
savedAddressService: saved_address_service.Service,
|
||||
|
|
|
@ -4,7 +4,6 @@ import ../../../../../app_service/service/transaction/service as transaction_ser
|
|||
import ../../../../../app_service/service/network/service as network_service
|
||||
import ../../../../../app_service/service/wallet_account/service as wallet_account_service
|
||||
import ../../../../../app_service/service/currency/service as currency_service
|
||||
import ../../../../../app_service/service/collectible/service as collectible_service
|
||||
import ../../../shared_modules/keycard_popup/io_interface as keycard_shared_module
|
||||
|
||||
import ../../../../core/[main]
|
||||
|
@ -82,10 +81,6 @@ proc init*(self: Controller) =
|
|||
# TODO: Rebuild Transaction items
|
||||
discard
|
||||
|
||||
self.events.on(SIGNAL_COLLECTIBLES_UPDATED) do(e:Args):
|
||||
# TODO: Refresh collectible data in Transaction items
|
||||
discard
|
||||
|
||||
self.events.on(SIGNAL_TRANSACTION_DECODED) do(e: Args):
|
||||
let args = TransactionDecodedArgs(e)
|
||||
self.delegate.txDecoded(args.txHash, args.dataDecoded)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import ../../../../../app_service/service/wallet_account/dto as WalletDto
|
||||
import ../../../../../app_service/service/collectible/dto as CollectibleDto
|
||||
import ../../../../../app_service/service/transaction/dto
|
||||
export TransactionDto, CollectibleDto
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ import ../../../../../app_service/service/transaction/service as transaction_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/currency/service as currency_service
|
||||
import ../../../../../app_service/service/collectible/service as collectible_service
|
||||
|
||||
export io_interface
|
||||
|
||||
|
@ -66,13 +65,6 @@ method transactionsToItems*(self: Module, transactions: seq[TransactionDto], col
|
|||
let ethFormat = self.controller.getCurrencyFormat("ETH")
|
||||
|
||||
transactions.map(t => (block:
|
||||
if t.typeValue == ERC721_TRANSACTION_TYPE:
|
||||
for c in collectibles:
|
||||
if c.tokenId == t.tokenId and c.address == t.contract:
|
||||
# Found matching collectible
|
||||
return transactionToNFTItem(t, c, ethFormat, gweiFormat)
|
||||
# Could not find matching collectible, use empty one
|
||||
return transactionToNFTItem(t, newCollectibleDto(), ethFormat, gweiFormat)
|
||||
let resolvedSymbol = self.getResolvedSymbol(t)
|
||||
return transactionToItem(t, resolvedSymbol, self.controller.getCurrencyFormat(resolvedSymbol), ethFormat, gweiFormat)
|
||||
))
|
||||
|
|
|
@ -3,7 +3,6 @@ import ../../../../global/global_singleton
|
|||
|
||||
import ../../../../../app_service/service/transaction/dto
|
||||
import ../../../../../app_service/service/currency/dto as currency_dto
|
||||
import ../../../../../app_service/service/collectible/dto as collectible_dto
|
||||
import ../../../shared/wallet_utils
|
||||
import ../../../shared_models/currency_amount
|
||||
|
||||
|
@ -54,36 +53,6 @@ proc transactionToItem*(t: TransactionDto, resolvedSymbol: string, tokenFormat:
|
|||
resolvedSymbol
|
||||
)
|
||||
|
||||
proc transactionToNFTItem*(t: TransactionDto, c: CollectibleDto, ethFormat: CurrencyFormatDto, gweiFormat: CurrencyFormatDto): Item =
|
||||
return initNFTItem(
|
||||
t.id,
|
||||
t.typeValue,
|
||||
t.address,
|
||||
t.blockNumber,
|
||||
t.blockHash,
|
||||
toInt(t.timestamp),
|
||||
hex2EthCurrencyAmount(t.gasPrice, ethFormat),
|
||||
parseInt(singletonInstance.utils.hex2Dec(t.gasLimit)),
|
||||
parseInt(singletonInstance.utils.hex2Dec(t.gasUsed)),
|
||||
t.nonce,
|
||||
t.txStatus,
|
||||
t.fromAddress,
|
||||
t.to,
|
||||
t.contract,
|
||||
t.chainId,
|
||||
hex2GweiCurrencyAmount(t.maxFeePerGas, gweiFormat),
|
||||
hex2GweiCurrencyAmount(t.maxPriorityFeePerGas, gweiFormat),
|
||||
t.input,
|
||||
t.txHash,
|
||||
t.multiTransactionID,
|
||||
hex2GweiCurrencyAmount(t.baseGasFees, gweiFormat),
|
||||
hex2GweiCurrencyAmount(t.totalFees, gweiFormat),
|
||||
hex2GweiCurrencyAmount(t.maxTotalFees, gweiFormat),
|
||||
t.tokenId,
|
||||
c.name,
|
||||
c.imageUrl
|
||||
)
|
||||
|
||||
proc multiTransactionToItem*(t: MultiTransactionDto): MultiTransactionItem =
|
||||
return initMultiTransactionItem(
|
||||
t.id,
|
||||
|
|
|
@ -3,7 +3,7 @@ import ./member_model, ./member_item
|
|||
import ../main/communities/models/[pending_request_item, pending_request_model]
|
||||
import ../main/communities/tokens/models/token_model as community_tokens_model
|
||||
import ../main/communities/tokens/models/token_item
|
||||
import ../../../app_service/service/collectible/dto
|
||||
from backend/collectibles_types import CollectibleOwner
|
||||
|
||||
import ../../global/global_singleton
|
||||
|
||||
|
|
|
@ -1,66 +0,0 @@
|
|||
type
|
||||
FetchOwnedCollectiblesTaskArg = ref object of QObjectTaskArg
|
||||
chainId*: int
|
||||
address*: string
|
||||
cursor: string
|
||||
limit: int
|
||||
|
||||
const fetchOwnedCollectiblesTaskArg: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
|
||||
let arg = decode[FetchOwnedCollectiblesTaskArg](argEncoded)
|
||||
try:
|
||||
let response = collectibles.getOpenseaAssetsByOwnerWithCursor(arg.chainId, arg.address, arg.cursor, arg.limit)
|
||||
|
||||
if not response.error.isNil:
|
||||
raise newException(ValueError, "Error getOpenseaAssetsByOwnerWithCursor" & response.error.message)
|
||||
|
||||
let output = %* {
|
||||
"chainId": arg.chainId,
|
||||
"address": arg.address,
|
||||
"cursor": arg.cursor,
|
||||
"collectibles": response.result,
|
||||
"error": ""
|
||||
}
|
||||
arg.finish(output)
|
||||
except Exception as e:
|
||||
let output = %* {
|
||||
"chainId": arg.chainId,
|
||||
"address": arg.address,
|
||||
"cursor": arg.cursor,
|
||||
"collectibles": "",
|
||||
"error": e.msg
|
||||
}
|
||||
arg.finish(output)
|
||||
|
||||
type
|
||||
FetchOwnedCollectiblesFromContractAddressesTaskArg = ref object of QObjectTaskArg
|
||||
chainId*: int
|
||||
address*: string
|
||||
contractAddresses*: seq[string]
|
||||
cursor: string
|
||||
limit: int
|
||||
|
||||
const fetchOwnedCollectiblesFromContractAddressesTaskArg: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
|
||||
let arg = decode[FetchOwnedCollectiblesFromContractAddressesTaskArg](argEncoded)
|
||||
try:
|
||||
let response = collectibles.getOpenseaAssetsByOwnerAndContractAddressWithCursor(arg.chainId, arg.address, arg.contractAddresses, arg.cursor, arg.limit)
|
||||
|
||||
if not response.error.isNil:
|
||||
raise newException(ValueError, "Error getOpenseaAssetsByOwnerAndContractAddressWithCursor" & response.error.message)
|
||||
|
||||
let output = %* {
|
||||
"chainId": arg.chainId,
|
||||
"address": arg.address,
|
||||
"cursor": arg.cursor,
|
||||
"collectibles": response.result,
|
||||
"error": ""
|
||||
}
|
||||
arg.finish(output)
|
||||
except Exception as e:
|
||||
let output = %* {
|
||||
"chainId": arg.chainId,
|
||||
"address": arg.address,
|
||||
"cursor": arg.cursor,
|
||||
"collectibles": "",
|
||||
"error": e.msg
|
||||
}
|
||||
arg.finish(output)
|
|
@ -1,177 +0,0 @@
|
|||
import json, Tables, stint, strformat, strutils
|
||||
|
||||
# Unique identifier for collectible on a specific chain
|
||||
type
|
||||
UniqueID* = object
|
||||
contractAddress*: string
|
||||
tokenId*: UInt256
|
||||
|
||||
type CollectibleTraitType* {.pure.} = enum
|
||||
Properties = 0,
|
||||
Rankings = 1,
|
||||
Statistics = 2
|
||||
|
||||
type CollectionTrait* = ref object
|
||||
min*, max*: float
|
||||
|
||||
type CollectionDto* = ref object
|
||||
name*, slug*, imageUrl*: string
|
||||
trait*: Table[string, CollectionTrait]
|
||||
|
||||
type CollectibleTrait* = ref object
|
||||
traitType*, value*, displayType*, maxValue*: string
|
||||
|
||||
type CollectibleDto* = ref object
|
||||
id*: int
|
||||
tokenId*: Uint256
|
||||
address*, collectionSlug*, name*, description*, permalink*, imageThumbnailUrl*, imageUrl*, animationUrl*, animationMediaType*, backgroundColor*: string
|
||||
properties*, rankings*, statistics*: seq[CollectibleTrait]
|
||||
|
||||
type CollectibleBalance* = ref object
|
||||
tokenId*: UInt256
|
||||
balance*: UInt256
|
||||
|
||||
proc `$`*(self: CollectibleBalance): string =
|
||||
return fmt"""CollectibleBalance(
|
||||
tokenId:{self.tokenId},
|
||||
balance:{self.balance}
|
||||
"""
|
||||
|
||||
type CollectibleOwner* = ref object
|
||||
address*: string
|
||||
balances*: seq[CollectibleBalance]
|
||||
|
||||
proc `$`*(self: CollectibleOwner): string =
|
||||
return fmt"""CollectibleOwner(
|
||||
address:{self.address},
|
||||
balances:{self.balances}
|
||||
"""
|
||||
|
||||
type CollectibleOwnershipDto* = ref object
|
||||
contractAddress*: string
|
||||
owners*: seq[CollectibleOwner]
|
||||
|
||||
proc `$`*(self: CollectibleOwnershipDto): string =
|
||||
return fmt"""CollectibleOwnershipDto(
|
||||
contractAddress:{self.contractAddress},
|
||||
owners:{self.owners}
|
||||
"""
|
||||
proc newCollectibleDto*: CollectibleDto =
|
||||
return CollectibleDto(
|
||||
id: -1
|
||||
)
|
||||
|
||||
proc isValid*(self: CollectibleDto): bool =
|
||||
return self.id >= 0
|
||||
|
||||
proc newCollectionDto*: CollectionDto =
|
||||
return CollectionDto(
|
||||
slug: ""
|
||||
)
|
||||
|
||||
proc isValid*(self: CollectionDto): bool =
|
||||
return self.slug != ""
|
||||
|
||||
proc isNumeric(s: string): bool =
|
||||
try:
|
||||
discard s.parseFloat()
|
||||
result = true
|
||||
except ValueError:
|
||||
result = false
|
||||
|
||||
proc `$`*(self: CollectionDto): string =
|
||||
return fmt"""CollectionDto(
|
||||
name:{self.name},
|
||||
slug:{self.slug},
|
||||
imageUrl:{self.imageUrl}
|
||||
"""
|
||||
|
||||
proc `$`*(self: CollectibleDto): string =
|
||||
return fmt"""CollectibleDto(
|
||||
id:{self.id},
|
||||
address:{self.address},
|
||||
tokenId:{self.tokenId},
|
||||
collectionSlug:{self.collectionSlug},
|
||||
name:{self.name},
|
||||
description:{self.description},
|
||||
permalink:{self.permalink},
|
||||
imageUrl: {self.imageUrl},
|
||||
imageThumbnailUrl: {self.imageThumbnailUrl},
|
||||
animationUrl: {self.animationUrl},
|
||||
animationMediaType: {self.animationMediaType},
|
||||
backgroundColor: {self.backgroundColor})
|
||||
"""
|
||||
|
||||
proc getCollectionTraits*(jsonCollection: JsonNode): Table[string, CollectionTrait] =
|
||||
var traitList: Table[string, CollectionTrait] = initTable[string, CollectionTrait]()
|
||||
for key, value in jsonCollection{"traits"}.getFields():
|
||||
traitList[key] = CollectionTrait(min: value{"min"}.getFloat, max: value{"max"}.getFloat)
|
||||
return traitList
|
||||
|
||||
proc toCollectionDto*(jsonCollection: JsonNode): CollectionDto =
|
||||
return CollectionDto(
|
||||
name: jsonCollection{"name"}.getStr,
|
||||
slug: jsonCollection{"slug"}.getStr,
|
||||
imageUrl: jsonCollection{"image_url"}.getStr,
|
||||
trait: getCollectionTraits(jsonCollection)
|
||||
)
|
||||
|
||||
proc getTrait*(jsonAsset: JsonNode, traitType: CollectibleTraitType): seq[CollectibleTrait] =
|
||||
var traitList: seq[CollectibleTrait] = @[]
|
||||
case traitType:
|
||||
of CollectibleTraitType.Properties:
|
||||
for index in jsonAsset{"traits"}.items:
|
||||
if((index{"display_type"}.getStr != "number") and (index{"display_type"}.getStr != "boost_percentage") and (index{"display_type"}.getStr != "boost_number") and not isNumeric(index{"value"}.getStr)):
|
||||
traitList.add(CollectibleTrait(traitType: index{"trait_type"}.getStr, value: index{"value"}.getStr, displayType: index{"display_type"}.getStr, maxValue: index{"max_value"}.getStr))
|
||||
of CollectibleTraitType.Rankings:
|
||||
for index in jsonAsset{"traits"}.items:
|
||||
if(index{"display_type"}.getStr != "number" and (index{"display_type"}.getStr != "boost_percentage") and (index{"display_type"}.getStr != "boost_number") and isNumeric(index{"value"}.getStr)):
|
||||
traitList.add(CollectibleTrait(traitType: index{"trait_type"}.getStr, value: index{"value"}.getStr, displayType: index{"display_type"}.getStr, maxValue: index{"max_value"}.getStr))
|
||||
of CollectibleTraitType.Statistics:
|
||||
for index in jsonAsset{"traits"}.items:
|
||||
if(index{"display_type"}.getStr == "number" and (index{"display_type"}.getStr != "boost_percentage") and (index{"display_type"}.getStr != "boost_number") and isNumeric(index{"value"}.getStr)):
|
||||
traitList.add(CollectibleTrait(traitType: index{"trait_type"}.getStr, value: index{"value"}.getStr, displayType: index{"display_type"}.getStr, maxValue: index{"max_value"}.getStr))
|
||||
return traitList
|
||||
|
||||
proc toCollectibleDto*(jsonAsset: JsonNode): CollectibleDto =
|
||||
return CollectibleDto(
|
||||
id: jsonAsset{"id"}.getInt,
|
||||
address: jsonAsset{"asset_contract"}{"address"}.getStr,
|
||||
tokenId: stint.parse(jsonAsset{"token_id"}.getStr, Uint256),
|
||||
collectionSlug: jsonAsset{"collection"}{"slug"}.getStr,
|
||||
name: jsonAsset{"name"}.getStr,
|
||||
description: jsonAsset{"description"}.getStr,
|
||||
permalink: jsonAsset{"permalink"}.getStr,
|
||||
imageThumbnailUrl: jsonAsset{"image_thumbnail_url"}.getStr,
|
||||
imageUrl: jsonAsset{"image_url"}.getStr,
|
||||
animationUrl: jsonAsset{"animation_url"}.getStr,
|
||||
animationMediaType: jsonAsset{"animation_media_type"}.getStr,
|
||||
backgroundColor: jsonAsset{"background_color"}.getStr,
|
||||
properties: getTrait(jsonAsset, CollectibleTraitType.Properties),
|
||||
rankings: getTrait(jsonAsset, CollectibleTraitType.Rankings),
|
||||
statistics: getTrait(jsonAsset, CollectibleTraitType.Statistics)
|
||||
)
|
||||
|
||||
proc getCollectibleBalances(jsonAsset: JsonNode): seq[CollectibleBalance] =
|
||||
var balanceList: seq[CollectibleBalance] = @[]
|
||||
for item in jsonAsset.items:
|
||||
balanceList.add(CollectibleBalance(
|
||||
tokenId: stint.parse(item{"tokenId"}.getStr, Uint256),
|
||||
balance: stint.parse(item{"balance"}.getStr, Uint256)
|
||||
))
|
||||
return balanceList
|
||||
|
||||
proc getCollectibleOwners(jsonAsset: JsonNode): seq[CollectibleOwner] =
|
||||
var ownerList: seq[CollectibleOwner] = @[]
|
||||
for item in jsonAsset.items:
|
||||
ownerList.add(CollectibleOwner(
|
||||
address: item{"ownerAddress"}.getStr,
|
||||
balances: getCollectibleBalances(item{"tokenBalances"})
|
||||
))
|
||||
return ownerList
|
||||
|
||||
proc toCollectibleOwnershipDto*(jsonAsset: JsonNode): CollectibleOwnershipDto =
|
||||
return CollectibleOwnershipDto(
|
||||
contractAddress: jsonAsset{"contractAddress"}.getStr,
|
||||
owners: getCollectibleOwners(jsonAsset{"owners"})
|
||||
)
|
|
@ -1,490 +0,0 @@
|
|||
import NimQml, Tables, chronicles, sequtils, json, sugar, stint, hashes, strformat, times, strutils
|
||||
import ../../../app/core/eventemitter
|
||||
import ../../../app/core/signals/types
|
||||
import ../../../app/core/tasks/[qt, threadpool]
|
||||
|
||||
import dto
|
||||
import ../network/service as network_service
|
||||
import ../wallet_account/service as wallet_account_service
|
||||
|
||||
import ../../../backend/collectibles as collectibles
|
||||
|
||||
include ../../common/json_utils
|
||||
include async_tasks
|
||||
|
||||
export dto
|
||||
|
||||
logScope:
|
||||
topics = "collectible-service"
|
||||
|
||||
# Signals which may be emitted by this service:
|
||||
const SIGNAL_OWNED_COLLECTIBLES_REFETCH* = "ownedCollectiblesRefetch"
|
||||
const SIGNAL_OWNED_COLLECTIBLES_UPDATE_STARTED* = "ownedCollectiblesUpdateStarted"
|
||||
const SIGNAL_OWNED_COLLECTIBLES_UPDATE_FINISHED* = "ownedCollectiblesUpdateFinished"
|
||||
const SIGNAL_OWNED_COLLECTIBLES_UPDATE_ERROR* = "ownedCollectiblesUpdateError"
|
||||
const SIGNAL_OWNED_COLLECTIBLES_FROM_WATCHED_CONTRACTS_FETCHED* = "ownedCollectiblesFromWatchedContractsFetched"
|
||||
const SIGNAL_COLLECTIBLES_UPDATED* = "collectiblesUpdated"
|
||||
|
||||
const INVALID_TIMESTAMP* = fromUnix(0)
|
||||
|
||||
# Maximum number of owned collectibles to be fetched at a time
|
||||
const ownedCollectiblesFetchLimit = 100
|
||||
|
||||
type
|
||||
OwnedCollectiblesUpdateArgs* = ref object of Args
|
||||
chainId*: int
|
||||
address*: string
|
||||
|
||||
type
|
||||
CollectiblesUpdateArgs* = ref object of Args
|
||||
chainId*: int
|
||||
ids*: seq[UniqueID]
|
||||
|
||||
type
|
||||
OwnedCollectible* = ref object of Args
|
||||
id*: UniqueID
|
||||
isFromWatchedContract*: bool
|
||||
|
||||
proc `$`*(self: OwnedCollectible): string =
|
||||
return fmt"""OwnedCollectible(
|
||||
id:{self.id},
|
||||
isFromWatchedContract:{self.isFromWatchedContract}
|
||||
)"""
|
||||
|
||||
type
|
||||
State {.pure.} = enum
|
||||
Init,
|
||||
WatchedContractsLoading,
|
||||
WatchedContractsLoaded,
|
||||
ChunkLoading,
|
||||
ChunkLoaded,
|
||||
AllLoaded,
|
||||
Error
|
||||
|
||||
type
|
||||
CollectiblesData* = ref object
|
||||
state*: State
|
||||
lastLoadCount*: int
|
||||
previousCursor*: string
|
||||
nextCursor*: string
|
||||
isRefetching*: bool
|
||||
lastRefetchTimestamp*: DateTime
|
||||
collectibles*: seq[OwnedCollectible]
|
||||
collectiblesFromWatchedContracts: seq[OwnedCollectible]
|
||||
|
||||
proc newCollectiblesData(): CollectiblesData =
|
||||
new(result)
|
||||
result.state = State.Init
|
||||
result.lastLoadCount = 0
|
||||
result.previousCursor = ""
|
||||
result.nextCursor = ""
|
||||
result.isRefetching = true
|
||||
result.lastRefetchTimestamp = INVALID_TIMESTAMP.utc()
|
||||
result.collectibles = @[]
|
||||
result.collectiblesFromWatchedContracts = @[]
|
||||
|
||||
proc prepareForRefetch(self: CollectiblesData) =
|
||||
self.state = State.Init
|
||||
self.lastLoadCount = 0
|
||||
self.previousCursor = ""
|
||||
self.nextCursor = ""
|
||||
self.isRefetching = true
|
||||
|
||||
proc isFetching*(self: CollectiblesData): bool =
|
||||
result = case self.state:
|
||||
of State.WatchedContractsLoading, State.ChunkLoading:
|
||||
true
|
||||
else:
|
||||
false
|
||||
|
||||
proc anyLoaded*(self: CollectiblesData): bool =
|
||||
return self.lastRefetchTimestamp != INVALID_TIMESTAMP.utc()
|
||||
|
||||
proc isError*(self: CollectiblesData): bool =
|
||||
return self.state == State.Error
|
||||
|
||||
proc allLoaded*(self: CollectiblesData): bool =
|
||||
return self.state == State.AllLoaded
|
||||
|
||||
proc `$`*(self: CollectiblesData): string =
|
||||
return fmt"""CollectiblesData(
|
||||
state:{self.state},
|
||||
lastLoadCount:{self.lastLoadCount},
|
||||
previousCursor:{self.previousCursor},
|
||||
nextCursor:{self.nextCursor},
|
||||
isRefetching:{self.isRefetching},
|
||||
lastRefetchTimestamp:{self.lastRefetchTimestamp},
|
||||
collectibles:{self.collectibles},
|
||||
collectiblesFromWatchedContracts:{self.collectiblesFromWatchedContracts}
|
||||
)"""
|
||||
|
||||
type
|
||||
OwnershipData* = ref object
|
||||
data*: CollectiblesData
|
||||
watchedContractAddresses*: seq[string]
|
||||
|
||||
proc newOwnershipData(): OwnershipData =
|
||||
new(result)
|
||||
result.data = newCollectiblesData()
|
||||
result.watchedContractAddresses = @[]
|
||||
|
||||
type
|
||||
AddressesData = TableRef[string, OwnershipData] # [address, OwnershipData]
|
||||
|
||||
proc newAddressesData(): AddressesData =
|
||||
result = newTable[string, OwnershipData]()
|
||||
|
||||
type
|
||||
ChainsData = TableRef[int, AddressesData] # [chainId, AddressesData]
|
||||
|
||||
proc newChainsData(): ChainsData =
|
||||
result = newTable[int, AddressesData]()
|
||||
|
||||
proc contains*(self: ChainsData, chainId: int, address: string): bool =
|
||||
return self.hasKey(chainId) and self[chainId].hasKey(address)
|
||||
|
||||
type
|
||||
CollectiblesResult = tuple[success: bool, collectibles: seq[CollectibleDto], collections: seq[CollectionDto], previousCursor: string, nextCursor: string]
|
||||
|
||||
proc hash(x: UniqueID): Hash =
|
||||
result = x.contractAddress.hash !& x.tokenId.hash
|
||||
result = !$result
|
||||
|
||||
QtObject:
|
||||
type
|
||||
Service* = ref object of QObject
|
||||
events: EventEmitter
|
||||
threadpool: ThreadPool
|
||||
networkService: network_service.Service
|
||||
accountsOwnershipData: ChainsData
|
||||
collectibles: TableRef[int, TableRef[UniqueID, CollectibleDto]] # [chainId, [UniqueID, CollectibleDto]]
|
||||
collections: TableRef[int, TableRef[string, CollectionDto]] # [chainId, [slug, CollectionDto]]
|
||||
|
||||
# Forward declarations
|
||||
proc refetchOwnedCollectibles*(self: Service, chainId: int, address: string)
|
||||
proc refetchAllOwnedCollectibles*(self: Service)
|
||||
proc removeAddress(self: Service, address: string)
|
||||
|
||||
proc delete*(self: Service) =
|
||||
self.QObject.delete
|
||||
|
||||
proc newService*(
|
||||
events: EventEmitter,
|
||||
threadpool: ThreadPool,
|
||||
networkService: network_service.Service,
|
||||
): Service =
|
||||
result = Service()
|
||||
result.QObject.setup
|
||||
result.events = events
|
||||
result.threadpool = threadpool
|
||||
result.networkService = networkService
|
||||
result.accountsOwnershipData = newChainsData()
|
||||
result.collectibles = newTable[int, TableRef[UniqueID, CollectibleDto]]()
|
||||
result.collections = newTable[int, TableRef[string, CollectionDto]]()
|
||||
|
||||
proc init*(self: Service) =
|
||||
self.events.on(SignalType.Wallet.event) do(e:Args):
|
||||
var data = WalletSignal(e)
|
||||
case data.eventType:
|
||||
of "wallet-tick-reload":
|
||||
self.refetchAllOwnedCollectibles()
|
||||
|
||||
self.events.on(SIGNAL_KEYPAIR_SYNCED) do(e: Args):
|
||||
let args = KeypairArgs(e)
|
||||
for acc in args.keypair.accounts:
|
||||
if acc.removed:
|
||||
self.removeAddress(acc.address)
|
||||
|
||||
self.events.on(SIGNAL_WALLET_ACCOUNT_DELETED) do(e:Args):
|
||||
self.removeAddress(AccountArgs(e).account.address)
|
||||
|
||||
# needs to be re-written once cache for colletibles works
|
||||
proc areCollectionsLoaded*(self: Service, address: string): bool =
|
||||
for chainId, adressesData in self.accountsOwnershipData:
|
||||
for addressData, ownershipData in adressesData:
|
||||
if addressData == address and ownershipData.data.anyLoaded:
|
||||
return true
|
||||
return false
|
||||
|
||||
proc prepareOwnershipData(self: Service, chainId: int, address: string) =
|
||||
if not self.accountsOwnershipData.hasKey(chainId):
|
||||
self.accountsOwnershipData[chainId] = newAddressesData()
|
||||
|
||||
let chainData = self.accountsOwnershipData[chainId]
|
||||
if not chainData.hasKey(address):
|
||||
chainData[address] = newOwnershipData()
|
||||
|
||||
proc processOwnedCollectiblesError(self: Service, chainId: int, address: string) =
|
||||
let ownershipData = self.accountsOwnershipData[chainId][address]
|
||||
let collectiblesData = ownershipData.data
|
||||
collectiblesData.lastLoadCount = 0
|
||||
collectiblesData.isRefetching = false
|
||||
collectiblesData.state = State.Error
|
||||
|
||||
var data = OwnedCollectiblesUpdateArgs()
|
||||
data.chainId = chainId
|
||||
data.address = address
|
||||
self.events.emit(SIGNAL_OWNED_COLLECTIBLES_UPDATE_ERROR, data)
|
||||
|
||||
proc updateOwnedCollectibles(self: Service, chainId: int, address: string, previousCursor: string, nextCursor: string, collectibles: seq[CollectibleDto]) =
|
||||
let ownershipData = self.accountsOwnershipData[chainId][address]
|
||||
let collectiblesData = ownershipData.data
|
||||
if not (collectiblesData.nextCursor == previousCursor):
|
||||
# Async response from an old fetch request, disregard
|
||||
return
|
||||
var isFromWatchedContract = false
|
||||
case collectiblesData.state:
|
||||
of State.WatchedContractsLoading:
|
||||
isFromWatchedContract = true
|
||||
collectiblesData.state = State.WatchedContractsLoaded
|
||||
# All fetched in one go, ignore cursors
|
||||
collectiblesData.previousCursor = ""
|
||||
collectiblesData.nextCursor = ""
|
||||
of State.ChunkLoading:
|
||||
if nextCursor == "":
|
||||
collectiblesData.state = State.AllLoaded
|
||||
else:
|
||||
collectiblesData.state = State.ChunkLoaded
|
||||
collectiblesData.previousCursor = previousCursor
|
||||
collectiblesData.nextCursor = nextCursor
|
||||
else:
|
||||
let errDescription = collectiblesData.state
|
||||
error "Invalid state", errDescription
|
||||
self.processOwnedCollectiblesError(chainId, address)
|
||||
|
||||
if collectiblesData.isRefetching:
|
||||
collectiblesData.isRefetching = false
|
||||
collectiblesData.lastRefetchTimestamp = now()
|
||||
collectiblesData.collectibles = @[]
|
||||
collectiblesData.collectiblesFromWatchedContracts = @[]
|
||||
|
||||
var count = 0
|
||||
for collectible in collectibles:
|
||||
let newId = UniqueID(
|
||||
contractAddress: collectible.address,
|
||||
tokenId: collectible.tokenId
|
||||
)
|
||||
if not collectiblesData.collectibles.any(c => newId == c.id):
|
||||
let ownedCollectible = OwnedCollectible(
|
||||
id: newId,
|
||||
isFromWatchedContract: isFromWatchedContract
|
||||
)
|
||||
collectiblesData.collectibles.add(ownedCollectible)
|
||||
if isFromWatchedContract:
|
||||
collectiblesData.collectiblesFromWatchedContracts.add(ownedCollectible)
|
||||
|
||||
count = count + 1
|
||||
collectiblesData.lastLoadCount = count
|
||||
|
||||
var data = OwnedCollectiblesUpdateArgs()
|
||||
data.chainId = chainId
|
||||
data.address = address
|
||||
if (collectiblesData.state == State.WatchedContractsLoaded):
|
||||
self.events.emit(SIGNAL_OWNED_COLLECTIBLES_FROM_WATCHED_CONTRACTS_FETCHED, data)
|
||||
self.events.emit(SIGNAL_OWNED_COLLECTIBLES_UPDATE_FINISHED, data)
|
||||
|
||||
proc updateCollectiblesCache*(self: Service, chainId: int, collectibles: seq[CollectibleDto], collections: seq[CollectionDto]) =
|
||||
if not self.collectibles.hasKey(chainId):
|
||||
self.collectibles[chainId] = newTable[UniqueID, CollectibleDto]()
|
||||
|
||||
if not self.collections.hasKey(chainId):
|
||||
self.collections[chainId] = newTable[string, CollectionDto]()
|
||||
|
||||
var data = CollectiblesUpdateArgs()
|
||||
data.chainId = chainId
|
||||
|
||||
for collection in collections:
|
||||
let slug = collection.slug
|
||||
self.collections[chainId][slug] = collection
|
||||
|
||||
for collectible in collectibles:
|
||||
let id = UniqueID(
|
||||
contractAddress: collectible.address,
|
||||
tokenId: collectible.tokenId
|
||||
)
|
||||
self.collectibles[chainId][id] = collectible
|
||||
data.ids.add(id)
|
||||
|
||||
self.events.emit(SIGNAL_COLLECTIBLES_UPDATED, data)
|
||||
|
||||
proc setWatchedContracts*(self: Service, chainId: int, address: string, contractAddresses: seq[string]) =
|
||||
self.prepareOwnershipData(chainId, address)
|
||||
self.accountsOwnershipData[chainId][address].watchedContractAddresses = contractAddresses
|
||||
# Re-fetch
|
||||
self.refetchOwnedCollectibles(chainId, address)
|
||||
|
||||
proc getOwnedCollectibles*(self: Service, chainId: int, addresses: seq[string]) : seq[CollectiblesData] =
|
||||
for address in addresses:
|
||||
self.prepareOwnershipData(chainId, address)
|
||||
result.add(self.accountsOwnershipData[chainId][address].data)
|
||||
|
||||
proc getCollectible*(self: Service, chainId: int, id: UniqueID) : CollectibleDto =
|
||||
try:
|
||||
return self.collectibles[chainId][id]
|
||||
except:
|
||||
discard
|
||||
return newCollectibleDto()
|
||||
|
||||
proc getCollection*(self: Service, chainId: int, slug: string) : CollectionDto =
|
||||
try:
|
||||
return self.collections[chainId][slug]
|
||||
except:
|
||||
discard
|
||||
return newCollectionDto()
|
||||
|
||||
proc processCollectiblesResult(responseObj: JsonNode) : CollectiblesResult =
|
||||
result.success = false
|
||||
let collectiblesContainerJson = responseObj["collectibles"]
|
||||
if collectiblesContainerJson.kind == JObject:
|
||||
let previousCursorJson = collectiblesContainerJson["previous"]
|
||||
let nextCursorJson = collectiblesContainerJson["next"]
|
||||
let collectiblesJson = collectiblesContainerJson["assets"]
|
||||
|
||||
if previousCursorJson.kind == JString and nextCursorJson.kind == JString:
|
||||
result.previousCursor = previousCursorJson.getStr()
|
||||
result.nextCursor = nextCursorJson.getStr()
|
||||
for collectibleJson in collectiblesJson.getElems():
|
||||
if collectibleJson.kind == JObject:
|
||||
result.collectibles.add(collectibleJson.toCollectibleDto())
|
||||
let collectionJson = collectibleJson["collection"]
|
||||
if collectionJson.kind == JObject:
|
||||
result.collections.add(collectionJson.toCollectionDto())
|
||||
else:
|
||||
return
|
||||
else:
|
||||
return
|
||||
result.success = true
|
||||
|
||||
proc onRxOwnedCollectibles(self: Service, response: string) {.slot.} =
|
||||
let responseObj = response.parseJson
|
||||
let chainIdJson = responseObj["chainId"]
|
||||
let addressJson = responseObj["address"]
|
||||
let chainId = chainIdJson.getInt()
|
||||
let address = addressJson.getStr()
|
||||
|
||||
if not self.accountsOwnershipData.contains(chainId, address):
|
||||
# Account was removed
|
||||
return
|
||||
|
||||
let collectiblesData = self.accountsOwnershipData[chainId][address].data
|
||||
|
||||
let errorStr = responseObj["error"].getStr()
|
||||
if errorStr != "":
|
||||
self.processOwnedCollectiblesError(chainId, address)
|
||||
error "error onRxOwnedCollectibles: ", errorStr
|
||||
else:
|
||||
let (success, collectibles, collections, prevCursor, nextCursor) = processCollectiblesResult(responseObj)
|
||||
if success:
|
||||
self.updateCollectiblesCache(chainId, collectibles, collections)
|
||||
self.updateOwnedCollectibles(chainId, address, prevCursor, nextCursor, collectibles)
|
||||
else:
|
||||
self.processOwnedCollectiblesError(chainId, address)
|
||||
let errDesription = "Could not get data from response"
|
||||
error "error onRxOwnedCollectibles: ", errDesription
|
||||
|
||||
proc fetchNextOwnedCollectiblesChunk(self: Service, chainId: int, address: string, limit: int = ownedCollectiblesFetchLimit) =
|
||||
self.prepareOwnershipData(chainId, address)
|
||||
|
||||
let ownershipData = self.accountsOwnershipData[chainId][address]
|
||||
let collectiblesData = ownershipData.data
|
||||
|
||||
var cursor = collectiblesData.nextCursor
|
||||
|
||||
let arg = FetchOwnedCollectiblesTaskArg(
|
||||
tptr: cast[ByteAddress](fetchOwnedCollectiblesTaskArg),
|
||||
vptr: cast[ByteAddress](self.vptr),
|
||||
slot: "onRxOwnedCollectibles",
|
||||
chainId: chainId,
|
||||
address: address,
|
||||
cursor: cursor,
|
||||
limit: limit
|
||||
)
|
||||
self.threadpool.start(arg)
|
||||
|
||||
proc onRxOwnedCollectiblesFromWatchedContractAddresses(self: Service, response: string) {.slot.} =
|
||||
let responseObj = response.parseJson
|
||||
let chainIdJson = responseObj["chainId"]
|
||||
let addressJson = responseObj["address"]
|
||||
let chainId = chainIdJson.getInt()
|
||||
let address = addressJson.getStr()
|
||||
|
||||
if not self.accountsOwnershipData.contains(chainId, address):
|
||||
# Account was removed
|
||||
return
|
||||
|
||||
let collectiblesData = self.accountsOwnershipData[chainId][address].data
|
||||
|
||||
let errorStr = responseObj["error"].getStr()
|
||||
if errorStr != "":
|
||||
self.processOwnedCollectiblesError(chainId, address)
|
||||
error "error onRxOwnedCollectiblesFromWatchedContractAddresses: ", errorStr
|
||||
else:
|
||||
let (success, collectibles, collections, prevCursor, nextCursor) = processCollectiblesResult(responseObj)
|
||||
if success:
|
||||
self.updateCollectiblesCache(chainId, collectibles, collections)
|
||||
self.updateOwnedCollectibles(chainId, address, prevCursor, nextCursor, collectibles)
|
||||
else:
|
||||
self.processOwnedCollectiblesError(chainId, address)
|
||||
let errDesription = "Could not get data from response"
|
||||
error "error onRxOwnedCollectiblesFromWatchedContractAddresses: ", errDesription
|
||||
|
||||
proc fetchOwnedCollectiblesFromWatchedContracts(self: Service, chainId: int, address: string) =
|
||||
let watchedContractAddresses = self.accountsOwnershipData[chainId][address].watchedContractAddresses
|
||||
|
||||
let arg = FetchOwnedCollectiblesFromContractAddressesTaskArg(
|
||||
tptr: cast[ByteAddress](fetchOwnedCollectiblesFromContractAddressesTaskArg),
|
||||
vptr: cast[ByteAddress](self.vptr),
|
||||
slot: "onRxOwnedCollectiblesFromWatchedContractAddresses",
|
||||
chainId: chainId,
|
||||
address: address,
|
||||
contractAddresses: watchedContractAddresses,
|
||||
cursor: "", # Always fetch from the beginning
|
||||
limit: 0 # Always fetch the complete list
|
||||
)
|
||||
self.threadpool.start(arg)
|
||||
|
||||
proc fetchOwnedCollectibles*(self: Service, chainId: int, addresses: seq[string], limit: int = ownedCollectiblesFetchLimit) =
|
||||
for address in addresses:
|
||||
self.prepareOwnershipData(chainId, address)
|
||||
|
||||
let ownershipData = self.accountsOwnershipData[chainId][address]
|
||||
let watchedContractAddresses = ownershipData.watchedContractAddresses
|
||||
let collectiblesData = ownershipData.data
|
||||
|
||||
let state = collectiblesData.state
|
||||
|
||||
if state == State.Init and len(watchedContractAddresses) > 0:
|
||||
collectiblesData.state = State.WatchedContractsLoading
|
||||
self.fetchOwnedCollectiblesFromWatchedContracts(chainId, address)
|
||||
elif state == State.Init or state == State.WatchedContractsLoaded or state == State.ChunkLoaded:
|
||||
collectiblesData.state = State.ChunkLoading
|
||||
self.fetchNextOwnedCollectiblesChunk(chainId, address)
|
||||
else:
|
||||
return
|
||||
|
||||
var data = OwnedCollectiblesUpdateArgs()
|
||||
data.chainId = chainId
|
||||
data.address = address
|
||||
self.events.emit(SIGNAL_OWNED_COLLECTIBLES_UPDATE_STARTED, data)
|
||||
|
||||
proc refetchOwnedCollectibles*(self: Service, chainId: int, address: string) =
|
||||
self.prepareOwnershipData(chainId, address)
|
||||
|
||||
let ownershipData = self.accountsOwnershipData[chainId][address]
|
||||
ownershipData.data.prepareForRefetch()
|
||||
|
||||
var data = OwnedCollectiblesUpdateArgs()
|
||||
data.chainId = chainId
|
||||
data.address = address
|
||||
self.events.emit(SIGNAL_OWNED_COLLECTIBLES_REFETCH, data)
|
||||
|
||||
self.fetchOwnedCollectibles(chainId, @[address])
|
||||
|
||||
proc refetchAllOwnedCollectibles*(self: Service) =
|
||||
for chainId, addressesData in self.accountsOwnershipData:
|
||||
for address, _ in addressesData:
|
||||
self.refetchOwnedCollectibles(chainId, address)
|
||||
|
||||
proc removeAddress(self: Service, address: string) =
|
||||
for chainId, addressesData in self.accountsOwnershipData:
|
||||
addressesData.del(address)
|
|
@ -11,7 +11,7 @@ import ../settings/service as settings_service
|
|||
import ../wallet_account/service as wallet_account_service
|
||||
import ../ens/utils as ens_utils
|
||||
import ../eth/dto/transaction
|
||||
import ../collectible/dto as collectibles_dto
|
||||
from backend/collectibles_types import CollectibleOwner
|
||||
|
||||
import ../../../backend/response_type
|
||||
|
||||
|
@ -813,7 +813,7 @@ QtObject:
|
|||
let contractAddress = responseJson["contractAddress"].getStr
|
||||
let communityId = responseJson["communityId"].getStr
|
||||
let resultJson = responseJson["result"]
|
||||
var owners = collectibles_dto.toCollectibleOwnershipDto(resultJson).owners
|
||||
var owners = fromJson(resultJson, CollectibleContractOwnership).owners
|
||||
owners = owners.filter(x => x.address != ZERO_ADDRESS)
|
||||
self.tokenOwnersCache[(chainId, contractAddress)] = owners
|
||||
let data = CommunityTokenOwnersArgs(chainId: chainId, contractAddress: contractAddress, communityId: communityId, owners: owners)
|
||||
|
|
|
@ -7,7 +7,6 @@ import ../../../app/core/signals/types
|
|||
import ../wallet_account/service as wallet_service
|
||||
import ../network/service as network_service
|
||||
import ../node/service as node_service
|
||||
import ../collectible/service as collectible_service
|
||||
|
||||
logScope:
|
||||
topics = "network-connection-service"
|
||||
|
@ -107,11 +106,6 @@ QtObject:
|
|||
let connectionStatus = self.connectionStatus[BLOCKCHAINS]
|
||||
self.updateBlockchainsStatus(connectionStatus.completelyDown, connectionStatus.chainIds, connectionStatus.lastCheckedAt)
|
||||
|
||||
self.events.on(SIGNAL_OWNED_COLLECTIBLES_UPDATE_ERROR) do(e:Args):
|
||||
if self.connectionStatus.hasKey(COLLECTIBLES):
|
||||
let connectionStatus = self.connectionStatus[COLLECTIBLES]
|
||||
self.updateMarketOrCollectibleStatus(COLLECTIBLES, connectionStatus.completelyDown, connectionStatus.lastCheckedAt)
|
||||
|
||||
proc getIsDown(self: Service, message: string): bool =
|
||||
result = message == "down"
|
||||
|
||||
|
|
|
@ -50,17 +50,6 @@ const loadTransactionsTask*: Task = proc(argEncoded: string) {.gcsafe, nimcall.}
|
|||
)
|
||||
if not uniqueIds.any(x => (x == nftId)):
|
||||
uniqueIds.add(nftId)
|
||||
|
||||
if len(uniqueIds) > 0:
|
||||
let collectiblesResponse = collectibles.getOpenseaAssetsByCollectibleUniqueID(uniqueIds)
|
||||
|
||||
if not collectiblesResponse.error.isNil:
|
||||
# We don't want to prevent getting the list of transactions if we cannot get
|
||||
# NFT metadata. Just don't return the metadata.
|
||||
let errDesription = "Error getOpenseaAssetsByCollectibleUniqueID" & collectiblesResponse.error.message
|
||||
error "error loadTransactionsTask: ", errDesription
|
||||
else:
|
||||
output["collectibles"] = collectiblesResponse.result
|
||||
except Exception as e:
|
||||
let errDesription = e.msg
|
||||
error "error loadTransactionsTask: ", errDesription
|
||||
|
|
|
@ -24,6 +24,11 @@ type
|
|||
proc event*(self:PendingTransactionTypeDto):string =
|
||||
result = "transaction:" & $self
|
||||
|
||||
# Deprecated type, to be removed along with transaction service/module
|
||||
type
|
||||
CollectibleDto* = ref object of RootObj
|
||||
dummy: string
|
||||
|
||||
type
|
||||
TransactionDto* = ref object of RootObj
|
||||
id*: string
|
||||
|
|
|
@ -16,7 +16,6 @@ import ../wallet_account/service as wallet_account_service
|
|||
import ../network/service as network_service
|
||||
import ../token/service as token_service
|
||||
import ../settings/service as settings_service
|
||||
import ../collectible/dto
|
||||
import ../eth/dto/transaction as transaction_data_dto
|
||||
import ../eth/dto/[coder, method_dto]
|
||||
import ./dto as transaction_dto
|
||||
|
@ -252,13 +251,6 @@ QtObject:
|
|||
self.allTransactions.mgetOrPut(address, initTable[string, TransactionDto]())[dto.txHash] = dto
|
||||
transactions.add(dto)
|
||||
|
||||
let collectiblesContainerJson = historyData["collectibles"]
|
||||
if collectiblesContainerJson.kind == JObject:
|
||||
let collectiblesJson = collectiblesContainerJson["assets"]
|
||||
if collectiblesJson.kind == JArray:
|
||||
for c in collectiblesJson.getElems():
|
||||
collectibles.add(c.toCollectibleDto())
|
||||
|
||||
if self.allTxLoaded.hasKey(address):
|
||||
self.allTxLoaded[address] = self.allTxLoaded[address] and allTxLoaded
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue