fix(wallet): Add token data when new token is added (#14061)
This commit is contained in:
parent
bbb0fd7222
commit
1deb5e86e5
|
@ -88,6 +88,8 @@ proc init*(self: Controller) =
|
||||||
self.communityTokensModule.onOwnerTokenReceived(args.communityId, args.communityName, args.chainId, args.contractAddress)
|
self.communityTokensModule.onOwnerTokenReceived(args.communityId, args.communityName, args.chainId, args.contractAddress)
|
||||||
self.events.on(SIGNAL_COMMUNITY_TOKEN_RECEIVED) do(e: Args):
|
self.events.on(SIGNAL_COMMUNITY_TOKEN_RECEIVED) do(e: Args):
|
||||||
let args = CommunityTokenReceivedArgs(e)
|
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.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):
|
self.events.on(SIGNAL_SET_SIGNER_STATUS) do(e: Args):
|
||||||
let args = SetSignerArgs(e)
|
let args = SetSignerArgs(e)
|
||||||
|
|
|
@ -48,6 +48,19 @@ proc init*(self: Controller) =
|
||||||
let args = TokenBalanceHistoryDataArgs(e)
|
let args = TokenBalanceHistoryDataArgs(e)
|
||||||
self.delegate.tokenBalanceHistoryDataResolved(args.result)
|
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()
|
self.tokenService.getSupportedTokensList()
|
||||||
|
|
||||||
proc getHistoricalDataForToken*(self: Controller, symbol: string, currency: string, range: int) =
|
proc getHistoricalDataForToken*(self: Controller, symbol: string, currency: string, range: int) =
|
||||||
|
|
|
@ -174,6 +174,7 @@ type
|
||||||
CommunityTokenReceivedArgs* = ref object of Args
|
CommunityTokenReceivedArgs* = ref object of Args
|
||||||
name*: string
|
name*: string
|
||||||
image*: string
|
image*: string
|
||||||
|
address*: string
|
||||||
collectibleId*: CollectibleUniqueID
|
collectibleId*: CollectibleUniqueID
|
||||||
communityId*: string
|
communityId*: string
|
||||||
communityName*: string
|
communityName*: string
|
||||||
|
@ -181,25 +182,33 @@ type
|
||||||
amount*: float64
|
amount*: float64
|
||||||
txHash*: string
|
txHash*: string
|
||||||
symbol*: string
|
symbol*: string
|
||||||
|
decimals*: int
|
||||||
|
verified*: bool
|
||||||
|
tokenListID*: string
|
||||||
isFirst*: bool
|
isFirst*: bool
|
||||||
tokenType*: int
|
tokenType*: int
|
||||||
accountAddress*: string
|
accountAddress*: string
|
||||||
accountName*: string
|
accountName*: string
|
||||||
|
isWatchOnlyAccount*: bool
|
||||||
|
|
||||||
proc `$`*(self: CommunityTokenReceivedArgs): string =
|
proc `$`*(self: CommunityTokenReceivedArgs): string =
|
||||||
return fmt"""CommunityTokenReceivedArgs(
|
return fmt"""CommunityTokenReceivedArgs(
|
||||||
name: {self.name}
|
name: {self.name},
|
||||||
image: {self.image}
|
image: {self.image},
|
||||||
communityId: {self.communityId}
|
communityId: {self.communityId},
|
||||||
communityName: {self.communityName}
|
communityName: {self.communityName},
|
||||||
chainId: {self.chainId}
|
chainId: {self.chainId},
|
||||||
amount: {self.amount}
|
amount: {self.amount},
|
||||||
txHash: {self.txHash}
|
decimals: {self.decimals},
|
||||||
symbol: {self.symbol}
|
verified: {self.verified},
|
||||||
isFirst: {self.isFirst}
|
tokenListID: {self.tokenListID},
|
||||||
tokenType: {self.tokenType}
|
txHash: {self.txHash},
|
||||||
accountAddress: {self.accountAddress}
|
symbol: {self.symbol},
|
||||||
accountName: {self.accountName}
|
isFirst: {self.isFirst},
|
||||||
|
tokenType: {self.tokenType},
|
||||||
|
accountAddress: {self.accountAddress},
|
||||||
|
accountName: {self.accountName},
|
||||||
|
isWatchOnlyAccount: {self.isWatchOnlyAccount}
|
||||||
)"""
|
)"""
|
||||||
|
|
||||||
proc toTokenData*(self: CommunityTokenReceivedArgs): string =
|
proc toTokenData*(self: CommunityTokenReceivedArgs): string =
|
||||||
|
@ -413,10 +422,6 @@ QtObject:
|
||||||
return
|
return
|
||||||
|
|
||||||
let watchOnlyAccounts = self.walletAccountService.getWatchOnlyAccounts()
|
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
|
var accountName, accountAddress: string
|
||||||
if len(accounts) > 0:
|
if len(accounts) > 0:
|
||||||
accountAddress = accounts[0]
|
accountAddress = accounts[0]
|
||||||
|
@ -429,14 +434,19 @@ QtObject:
|
||||||
communityName: tokenDataPayload.communityName,
|
communityName: tokenDataPayload.communityName,
|
||||||
chainId: tokenDataPayload.chainId,
|
chainId: tokenDataPayload.chainId,
|
||||||
txHash: tokenDataPayload.txHash,
|
txHash: tokenDataPayload.txHash,
|
||||||
|
address: "0x" & tokenDataPayload.address.toHex(),
|
||||||
name: tokenDataPayload.name,
|
name: tokenDataPayload.name,
|
||||||
amount: tokenDataPayload.amount,
|
amount: tokenDataPayload.amount,
|
||||||
|
decimals: tokenDataPayload.decimals,
|
||||||
|
verified: tokenDataPayload.verified,
|
||||||
|
tokenListID: tokenDataPayload.tokenListID,
|
||||||
image: tokenDataPayload.image,
|
image: tokenDataPayload.image,
|
||||||
symbol: tokenDataPayload.symbol,
|
symbol: tokenDataPayload.symbol,
|
||||||
isFirst: tokenDataPayload.isFirst,
|
isFirst: tokenDataPayload.isFirst,
|
||||||
tokenType: int(TokenType.ERC20),
|
tokenType: int(TokenType.ERC20),
|
||||||
accountAddress: accountAddress,
|
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)
|
self.events.emit(SIGNAL_COMMUNITY_TOKEN_RECEIVED, tokenReceivedArgs)
|
||||||
|
|
||||||
|
|
|
@ -219,6 +219,45 @@ QtObject:
|
||||||
let errDesription = e.msg
|
let errDesription = e.msg
|
||||||
error "error: ", errDesription
|
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
|
# Callback to process the response of getSupportedTokensList call
|
||||||
proc supportedTokensListRetrieved(self: Service, response: string) {.slot.} =
|
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
|
# 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)
|
var data = WalletSignal(e)
|
||||||
case data.eventType:
|
case data.eventType:
|
||||||
of "wallet-tick-reload":
|
of "wallet-tick-reload":
|
||||||
self.rebuildMarketData()
|
self.rebuildMarketData()
|
||||||
# update and populate internal list and then emit signal when new custom token detected?
|
# update and populate internal list and then emit signal when new custom token detected?
|
||||||
|
|
||||||
proc getCurrency*(self: Service): string =
|
proc getCurrency*(self: Service): string =
|
||||||
|
|
|
@ -14,6 +14,9 @@ type
|
||||||
symbol*: string
|
symbol*: string
|
||||||
image*: string
|
image*: string
|
||||||
chainId*: int
|
chainId*: int
|
||||||
|
decimals*: int
|
||||||
|
verified*: bool
|
||||||
|
tokenListID*: string
|
||||||
communityId*: string
|
communityId*: string
|
||||||
communityName*: string
|
communityName*: string
|
||||||
communityColor*: string
|
communityColor*: string
|
||||||
|
@ -28,6 +31,9 @@ proc fromJson*(t: JsonNode, T: typedesc[CommunityTokenReceivedPayload]): Communi
|
||||||
discard t.getProp("symbol", result.symbol)
|
discard t.getProp("symbol", result.symbol)
|
||||||
discard t.getProp("image", result.image)
|
discard t.getProp("image", result.image)
|
||||||
discard t.getProp("chainId", result.chainId)
|
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("txHash", result.txHash)
|
||||||
discard t.getProp("isFirst", result.isFirst)
|
discard t.getProp("isFirst", result.isFirst)
|
||||||
discard t.getProp("amount", result.amount)
|
discard t.getProp("amount", result.amount)
|
||||||
|
|
|
@ -55,6 +55,7 @@ StatusListItem {
|
||||||
return "▴"
|
return "▴"
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
readonly property bool isUndefined: modelData && !modelData.marketDetailsLoading && title === ""
|
||||||
|
|
||||||
signal switchToCommunityRequested(string communityId)
|
signal switchToCommunityRequested(string communityId)
|
||||||
|
|
||||||
|
@ -65,6 +66,8 @@ StatusListItem {
|
||||||
asset.width: 32
|
asset.width: 32
|
||||||
asset.height: 32
|
asset.height: 32
|
||||||
errorIcon.tooltip.maxWidth: 300
|
errorIcon.tooltip.maxWidth: 300
|
||||||
|
height: isUndefined ? 0 : implicitHeight
|
||||||
|
visible: !isUndefined
|
||||||
|
|
||||||
statusListItemTitleIcons.sourceComponent: StatusFlatRoundButton {
|
statusListItemTitleIcons.sourceComponent: StatusFlatRoundButton {
|
||||||
width: 14
|
width: 14
|
||||||
|
|
Loading…
Reference in New Issue