fix(wallet): Add token data when new token is added
This commit is contained in:
parent
489b02c598
commit
1a0900ae91
|
@ -88,6 +88,8 @@ proc init*(self: Controller) =
|
|||
self.communityTokensModule.onOwnerTokenReceived(args.communityId, args.communityName, args.chainId, args.contractAddress)
|
||||
self.events.on(SIGNAL_COMMUNITY_TOKEN_RECEIVED) do(e: Args):
|
||||
let args = CommunityTokenReceivedArgs(e)
|
||||
if args.isWatchOnlyAccount:
|
||||
return
|
||||
self.communityTokensModule.onCommunityTokenReceived(args.name, args.symbol, args.image, args.communityId, args.communityName, $args.amount, args.chainId, args.txHash, args.isFirst, args.tokenType, args.accountName, args.accountAddress)
|
||||
self.events.on(SIGNAL_SET_SIGNER_STATUS) do(e: Args):
|
||||
let args = SetSignerArgs(e)
|
||||
|
|
|
@ -48,6 +48,19 @@ proc init*(self: Controller) =
|
|||
let args = TokenBalanceHistoryDataArgs(e)
|
||||
self.delegate.tokenBalanceHistoryDataResolved(args.result)
|
||||
|
||||
self.events.on(SIGNAL_COMMUNITY_TOKEN_RECEIVED) do(e: Args):
|
||||
let args = CommunityTokenReceivedArgs(e)
|
||||
let token = TokenDto(
|
||||
address: args.address,
|
||||
name: args.name,
|
||||
symbol: args.symbol,
|
||||
decimals: args.decimals,
|
||||
chainID: args.chainId,
|
||||
communityID: args.communityId,
|
||||
image: args.image,
|
||||
)
|
||||
self.tokenService.addNewCommunityToken(token)
|
||||
|
||||
self.tokenService.getSupportedTokensList()
|
||||
|
||||
proc getHistoricalDataForToken*(self: Controller, symbol: string, currency: string, range: int) =
|
||||
|
|
|
@ -174,6 +174,7 @@ type
|
|||
CommunityTokenReceivedArgs* = ref object of Args
|
||||
name*: string
|
||||
image*: string
|
||||
address*: string
|
||||
collectibleId*: CollectibleUniqueID
|
||||
communityId*: string
|
||||
communityName*: string
|
||||
|
@ -181,25 +182,33 @@ type
|
|||
amount*: float64
|
||||
txHash*: string
|
||||
symbol*: string
|
||||
decimals*: int
|
||||
verified*: bool
|
||||
tokenListID*: string
|
||||
isFirst*: bool
|
||||
tokenType*: int
|
||||
accountAddress*: string
|
||||
accountName*: string
|
||||
isWatchOnlyAccount*: bool
|
||||
|
||||
proc `$`*(self: CommunityTokenReceivedArgs): string =
|
||||
return fmt"""CommunityTokenReceivedArgs(
|
||||
name: {self.name}
|
||||
image: {self.image}
|
||||
communityId: {self.communityId}
|
||||
communityName: {self.communityName}
|
||||
chainId: {self.chainId}
|
||||
amount: {self.amount}
|
||||
txHash: {self.txHash}
|
||||
symbol: {self.symbol}
|
||||
isFirst: {self.isFirst}
|
||||
tokenType: {self.tokenType}
|
||||
accountAddress: {self.accountAddress}
|
||||
accountName: {self.accountName}
|
||||
name: {self.name},
|
||||
image: {self.image},
|
||||
communityId: {self.communityId},
|
||||
communityName: {self.communityName},
|
||||
chainId: {self.chainId},
|
||||
amount: {self.amount},
|
||||
decimals: {self.decimals},
|
||||
verified: {self.verified},
|
||||
tokenListID: {self.tokenListID},
|
||||
txHash: {self.txHash},
|
||||
symbol: {self.symbol},
|
||||
isFirst: {self.isFirst},
|
||||
tokenType: {self.tokenType},
|
||||
accountAddress: {self.accountAddress},
|
||||
accountName: {self.accountName},
|
||||
isWatchOnlyAccount: {self.isWatchOnlyAccount}
|
||||
)"""
|
||||
|
||||
proc toTokenData*(self: CommunityTokenReceivedArgs): string =
|
||||
|
@ -413,10 +422,6 @@ QtObject:
|
|||
return
|
||||
|
||||
let watchOnlyAccounts = self.walletAccountService.getWatchOnlyAccounts()
|
||||
if any(watchOnlyAccounts, proc (x: WalletAccountDto): bool = x.address == accounts[0]):
|
||||
# skip events on watch-only accounts
|
||||
return
|
||||
|
||||
var accountName, accountAddress: string
|
||||
if len(accounts) > 0:
|
||||
accountAddress = accounts[0]
|
||||
|
@ -429,14 +434,19 @@ QtObject:
|
|||
communityName: tokenDataPayload.communityName,
|
||||
chainId: tokenDataPayload.chainId,
|
||||
txHash: tokenDataPayload.txHash,
|
||||
address: "0x" & tokenDataPayload.address.toHex(),
|
||||
name: tokenDataPayload.name,
|
||||
amount: tokenDataPayload.amount,
|
||||
decimals: tokenDataPayload.decimals,
|
||||
verified: tokenDataPayload.verified,
|
||||
tokenListID: tokenDataPayload.tokenListID,
|
||||
image: tokenDataPayload.image,
|
||||
symbol: tokenDataPayload.symbol,
|
||||
isFirst: tokenDataPayload.isFirst,
|
||||
tokenType: int(TokenType.ERC20),
|
||||
accountAddress: accountAddress,
|
||||
accountName: accountName
|
||||
accountName: accountName,
|
||||
isWatchOnlyAccount: any(watchOnlyAccounts, proc (x: WalletAccountDto): bool = x.address == accounts[0])
|
||||
)
|
||||
self.events.emit(SIGNAL_COMMUNITY_TOKEN_RECEIVED, tokenReceivedArgs)
|
||||
|
||||
|
|
|
@ -219,6 +219,45 @@ QtObject:
|
|||
let errDesription = e.msg
|
||||
error "error: ", errDesription
|
||||
|
||||
proc addNewCommunityToken*(self: Service, token: TokenDto) =
|
||||
let sourceName = "custom"
|
||||
let tokenType = TokenType.ERC20
|
||||
|
||||
var updated = false
|
||||
let unique_key = $token.chainID & token.address
|
||||
if not any(self.flatTokenList, proc (x: TokenItem): bool = x.key == unique_key):
|
||||
self.flatTokenList.add(TokenItem(
|
||||
key: unique_key,
|
||||
name: token.name,
|
||||
symbol: token.symbol,
|
||||
sources: @[sourceName],
|
||||
chainID: token.chainID,
|
||||
address: token.address,
|
||||
decimals: token.decimals,
|
||||
image: token.image,
|
||||
`type`: tokenType,
|
||||
communityId: token.communityID))
|
||||
self.flatTokenList.sort(cmpTokenItem)
|
||||
updated = true
|
||||
|
||||
let token_by_symbol_key = token.address
|
||||
if not any(self.tokenBySymbolList, proc (x: TokenBySymbolItem): bool = x.key == token_by_symbol_key):
|
||||
self.tokenBySymbolList.add(TokenBySymbolItem(
|
||||
key: token_by_symbol_key,
|
||||
name: token.name,
|
||||
symbol: token.symbol,
|
||||
sources: @[sourceName],
|
||||
addressPerChainId: @[AddressPerChain(chainId: token.chainID, address: token.address)],
|
||||
decimals: token.decimals,
|
||||
image: token.image,
|
||||
`type`: tokenType,
|
||||
communityId: token.communityID))
|
||||
self.tokenBySymbolList.sort(cmpTokenBySymbolItem)
|
||||
updated = true
|
||||
|
||||
if updated:
|
||||
self.events.emit(SIGNAL_TOKENS_LIST_UPDATED, Args())
|
||||
|
||||
# Callback to process the response of getSupportedTokensList call
|
||||
proc supportedTokensListRetrieved(self: Service, response: string) {.slot.} =
|
||||
# this is emited so that the models can know that the seq it depends on has been updated
|
||||
|
@ -329,7 +368,7 @@ QtObject:
|
|||
var data = WalletSignal(e)
|
||||
case data.eventType:
|
||||
of "wallet-tick-reload":
|
||||
self.rebuildMarketData()
|
||||
self.rebuildMarketData()
|
||||
# update and populate internal list and then emit signal when new custom token detected?
|
||||
|
||||
proc getCurrency*(self: Service): string =
|
||||
|
|
|
@ -14,6 +14,9 @@ type
|
|||
symbol*: string
|
||||
image*: string
|
||||
chainId*: int
|
||||
decimals*: int
|
||||
verified*: bool
|
||||
tokenListID*: string
|
||||
communityId*: string
|
||||
communityName*: string
|
||||
communityColor*: string
|
||||
|
@ -28,6 +31,9 @@ proc fromJson*(t: JsonNode, T: typedesc[CommunityTokenReceivedPayload]): Communi
|
|||
discard t.getProp("symbol", result.symbol)
|
||||
discard t.getProp("image", result.image)
|
||||
discard t.getProp("chainId", result.chainId)
|
||||
discard t.getProp("decimals", result.decimals)
|
||||
discard t.getProp("verified", result.verified)
|
||||
discard t.getProp("tokenListID", result.tokenListID)
|
||||
discard t.getProp("txHash", result.txHash)
|
||||
discard t.getProp("isFirst", result.isFirst)
|
||||
discard t.getProp("amount", result.amount)
|
||||
|
|
|
@ -55,6 +55,7 @@ StatusListItem {
|
|||
return "▴"
|
||||
return ""
|
||||
}
|
||||
readonly property bool isUndefined: modelData && !modelData.marketDetailsLoading && title === ""
|
||||
|
||||
signal switchToCommunityRequested(string communityId)
|
||||
|
||||
|
@ -65,6 +66,8 @@ StatusListItem {
|
|||
asset.width: 32
|
||||
asset.height: 32
|
||||
errorIcon.tooltip.maxWidth: 300
|
||||
height: isUndefined ? 0 : implicitHeight
|
||||
visible: !isUndefined
|
||||
|
||||
statusListItemTitleIcons.sourceComponent: StatusFlatRoundButton {
|
||||
width: 14
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit a079b00d3d300fce753f1babb86e323efc42c61f
|
||||
Subproject commit d8a93141f6da4da70c360e0362f7ce2260788d9f
|
Loading…
Reference in New Issue