Skip to content

Commit c5c43c8

Browse files
committed
init
1 parent b492185 commit c5c43c8

File tree

181 files changed

+2929
-2745
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+2929
-2745
lines changed

src/app/core/signals/remote_signals/wallet.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ proc fromEvent*(T: type WalletSignal, signalType: SignalType, jsonSignal: JsonNo
109109
result.errorCode = errorResponseJsonNode["code"].getStr
110110
result.updatedPrices = initTable[string, float64]()
111111
if event.contains("UpdatedPrices"):
112-
for tokenSymbol, price in event["UpdatedPrices"].pairs():
113-
result.updatedPrices[tokenSymbol] = price.getFloat
112+
for tokenKey, price in event["UpdatedPrices"].pairs():
113+
result.updatedPrices[tokenKey] = price.getFloat
114114
except Exception as e:
115115
error "Error parsing best route: ", err=e.msg
116116
return

src/app/modules/main/browser_section/current_account/controller.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ proc getEnabledChainIds*(self: Controller): seq[int] =
5050
proc getCurrentCurrency*(self: Controller): string =
5151
return self.walletAccountService.getCurrency()
5252

53-
proc getCurrencyFormat*(self: Controller, symbol: string): CurrencyFormatDto =
54-
return self.currencyService.getCurrencyFormat(symbol)
53+
proc getCurrencyFormat*(self: Controller, key: string): CurrencyFormatDto =
54+
return self.currencyService.getCurrencyFormat(key)
5555

5656
proc areTestNetworksEnabled*(self: Controller): bool =
5757
return self.walletAccountService.areTestNetworksEnabled()

src/app/modules/main/chat_section/chat_content/input_area/view.nim

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import nimqml, sets
22
import ./io_interface
33
import ./preserved_properties
44
import ./urls_model
5-
import ../../../../../../app/modules/shared_models/link_preview_model as link_preview_model
6-
import ../../../../../../app/modules/shared_models/payment_request_model as payment_request_model
7-
import ../../../../../../app/modules/shared_models/default_emoji_reactions_model as default_emoji_reactions_model
5+
import app/modules/shared_models/link_preview_model as link_preview_model
6+
import app/modules/shared_models/payment_request_model as payment_request_model
7+
import app/modules/shared_models/default_emoji_reactions_model as default_emoji_reactions_model
88

99
QtObject:
1010
type
@@ -89,7 +89,7 @@ QtObject:
8989
QtProperty[bool] askToEnableLinkPreview:
9090
read = getAskToEnableLinkPreview
9191
notify = askToEnableLinkPreviewChanged
92-
92+
9393
# Currently used to fetch link previews, but could be used elsewhere
9494
proc setText*(self: View, text: string) {.slot.} =
9595
self.delegate.setText(text, true)
@@ -100,7 +100,7 @@ QtObject:
100100
proc updateLinkPreviewsFromCache*(self: View, urls: seq[string]) =
101101
let linkPreviews = self.delegate.linkPreviewsFromCache(urls)
102102
self.linkPreviewModel.updateLinkPreviews(linkPreviews)
103-
103+
104104
for contactId in self.linkPreviewModel.getContactIds().items:
105105
let contact = self.delegate.getContactDetails(contactId)
106106
if contact.dto.displayName != "":
@@ -115,25 +115,25 @@ QtObject:
115115

116116
proc reloadLinkPreview(self: View, link: string) {.slot.} =
117117
self.delegate.loadLinkPreviews(@[link])
118-
118+
119119
proc loadLinkPreviews(self: View, links: seq[string]) =
120120
self.delegate.loadLinkPreviews(links)
121-
121+
122122
proc enableLinkPreview(self: View) {.slot.} =
123123
self.delegate.setLinkPreviewEnabled(true)
124-
124+
125125
proc disableLinkPreview(self: View) {.slot.} =
126126
self.delegate.setLinkPreviewEnabled(false)
127-
127+
128128
proc setLinkPreviewEnabledForCurrentMessage(self: View, enabled: bool) {.slot.} =
129129
self.delegate.setLinkPreviewEnabledForThisMessage(enabled)
130130
self.delegate.reloadUnfurlingPlan()
131131

132132
proc removeLinkPreviewData*(self: View, index: int) {.slot.} =
133133
self.linkPreviewModel.removePreviewData(index)
134134

135-
proc addPaymentRequest*(self: View, receiver: string, amount: string, symbol: string, chainId: int) {.slot.} =
136-
self.paymentRequestModel.addPaymentRequest(receiver, amount, symbol, chainId)
135+
proc addPaymentRequest*(self: View, receiver: string, amount: string, tokenKey: string, symbol: string) {.slot.} =
136+
self.paymentRequestModel.addPaymentRequest(receiver, amount, tokenKey, symbol)
137137

138138
proc removePaymentRequestPreviewData*(self: View, index: int) {.slot.} =
139139
self.paymentRequestModel.removeItemWithIndex(index)

src/app/modules/main/chat_section/controller.nim

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import ../../../core/signals/types
2121
import ../../../core/eventemitter
2222
import ../../../core/unique_event_emitter
2323

24-
import backend/collectibles_types
24+
# import backend/collectibles_types
2525

2626
type
2727
Controller* = ref object of RootObj
@@ -279,7 +279,7 @@ proc init*(self: Controller) =
279279
let args = CommunityTokenPermissionArgs(e)
280280
if (args.communityId == self.sectionId):
281281
self.delegate.onCommunityTokenPermissionUpdated(args.communityId, args.tokenPermission)
282-
282+
283283
self.events.on(SIGNAL_COMMUNITY_TOKEN_PERMISSION_DELETED) do(e: Args):
284284
let args = CommunityTokenPermissionArgs(e)
285285
if (args.communityId == self.sectionId):
@@ -712,45 +712,15 @@ proc getMessagesParsedPlainText*(self: Controller, message: MessageDto, communit
712712
proc getColorId*(self: Controller, pubkey: string): int =
713713
procs_from_visual_identity_service.colorIdOf(pubkey)
714714

715+
proc getTokenByKey*(self: Controller, tokenKey: string): TokenItem =
716+
return self.tokenService.getTokenByKey(tokenKey)
717+
715718
proc createOrEditCommunityTokenPermission*(self: Controller, tokenPermission: CommunityTokenPermissionDto) =
716719
self.communityService.createOrEditCommunityTokenPermission(self.sectionId, tokenPermission)
717720

718721
proc deleteCommunityTokenPermission*(self: Controller, permissionId: string) =
719722
self.communityService.deleteCommunityTokenPermission(self.sectionId, permissionId)
720723

721-
proc allAccountsTokenBalance*(self: Controller, symbol: string): float64 =
722-
return self.walletAccountService.allAccountsTokenBalance(symbol)
723-
724-
proc getTokenDecimals*(self: Controller, symbol: string): int =
725-
let asset = self.tokenService.findTokenBySymbol(symbol)
726-
if asset != nil:
727-
return asset.decimals
728-
return 0
729-
730-
# find addresses by tokenKey from UI
731-
# tokenKey can be: symbol for ERC20, or chain+address[+tokenId] for ERC721
732-
proc getContractAddressesForToken*(self: Controller, tokenKey: string): Table[int, string] =
733-
var contractAddresses = initTable[int, string]()
734-
let token = self.tokenService.findTokenBySymbol(tokenKey)
735-
if token != nil:
736-
for addrPerChain in token.addressPerChainId:
737-
# depending on areTestNetworksEnabled (in getNetworkByChainId), contractAddresses will
738-
# contain mainnets or testnets only
739-
let network = self.networkService.getNetworkByChainId(addrPerChain.chainId)
740-
if network == nil:
741-
continue
742-
contractAddresses[addrPerChain.chainId] = addrPerChain.address
743-
let communityToken = self.communityService.getCommunityTokenBySymbol(self.getMySectionId(), tokenKey)
744-
if communityToken.address != "":
745-
contractAddresses[communityToken.chainId] = communityToken.address
746-
if contractAddresses.len == 0:
747-
try:
748-
let chainAndAddress = toContractID(tokenKey)
749-
contractAddresses[chainAndAddress.chainID] = chainAndAddress.address
750-
except Exception:
751-
discard
752-
return contractAddresses
753-
754724
proc getCommunityTokenList*(self: Controller): seq[CommunityTokenDto] =
755725
return self.communityTokensService.getCommunityTokens(self.getMySectionId())
756726

src/app/modules/main/chat_section/module.nim

Lines changed: 45 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,36 @@ import ../io_interface as delegate_interface
55
import view, controller, active_item
66
import model as chats_model
77
import item as chat_item
8-
import ../../shared_models/message_item as member_msg_item
9-
import ../../shared_models/message_model as member_msg_model
10-
import ../../shared_models/user_item as user_item
11-
import ../../shared_models/user_model as user_model
12-
import ../../shared_models/[token_permissions_model, token_permission_item, token_criteria_item, token_criteria_model, token_permission_chat_list_model, contacts_utils]
8+
9+
import app/modules/shared_models/message_item as member_msg_item
10+
import app/modules/shared_models/message_model as member_msg_model
11+
import app/modules/shared_models/user_item as user_item
12+
import app/modules/shared_models/user_model as user_model
13+
import app/modules/shared_models/[token_permissions_model, token_permission_item, token_criteria_item, token_criteria_model, token_permission_chat_list_model, contacts_utils]
1314

1415
import chat_content/module as chat_content_module
1516
import chat_content/users/module as users_module
1617

17-
import ../../../global/global_singleton
18-
import ../../../core/eventemitter
19-
import ../../../core/unique_event_emitter
20-
import ../../../core/notifications/details as notification_details
21-
import ../../../../app_service/common/types
22-
import ../../../../app_service/service/settings/service as settings_service
23-
import ../../../../app_service/service/node_configuration/service as node_configuration_service
24-
import ../../../../app_service/service/contacts/service as contact_service
25-
import ../../../../app_service/service/chat/service as chat_service
26-
import ../../../../app_service/service/network/service as network_service
27-
import ../../../../app_service/service/community/service as community_service
28-
import ../../../../app_service/service/message/service as message_service
29-
import ../../../../app_service/service/mailservers/service as mailservers_service
30-
import ../../../../app_service/service/wallet_account/service as wallet_account_service
31-
import ../../../../app_service/service/token/service as token_service
32-
import ../../../../app_service/service/community_tokens/service as community_tokens_service
33-
import ../../../../app_service/service/shared_urls/service as shared_urls_service
34-
import ../../../../app_service/service/contacts/dto/contacts as contacts_dto
35-
import ../../../../app/core/signals/types
18+
import app/global/global_singleton
19+
import app/core/eventemitter
20+
import app/core/unique_event_emitter
21+
import app/core/notifications/details as notification_details
22+
import app_service/common/types
23+
import app_service/common/utils as service_common_utils
24+
import app_service/service/settings/service as settings_service
25+
import app_service/service/node_configuration/service as node_configuration_service
26+
import app_service/service/contacts/service as contact_service
27+
import app_service/service/chat/service as chat_service
28+
import app_service/service/network/service as network_service
29+
import app_service/service/community/service as community_service
30+
import app_service/service/message/service as message_service
31+
import app_service/service/mailservers/service as mailservers_service
32+
import app_service/service/wallet_account/service as wallet_account_service
33+
import app_service/service/token/service as token_service
34+
import app_service/service/community_tokens/service as community_tokens_service
35+
import app_service/service/shared_urls/service as shared_urls_service
36+
import app_service/service/contacts/dto/contacts as contacts_dto
37+
import app/core/signals/types
3638

3739
export io_interface
3840

@@ -369,7 +371,7 @@ method onChatsLoaded*(
369371
sharedUrlsService: shared_urls_service.Service,
370372
) =
371373
self.chatsLoaded = true
372-
374+
373375
self.buildChatSectionUI(community, chats, events, settingsService, nodeConfigurationService,
374376
contactService, chatService, communityService, messageService, mailserversService, sharedUrlsService)
375377

@@ -451,7 +453,7 @@ method activeItemSet*(self: Module, itemId: string) =
451453
# Should never be here
452454
error "chat-view unexisting item id: ", itemId, methodName="activeItemSet"
453455
return
454-
456+
455457
if not self.chatContentModules[itemId].isLoaded:
456458
self.chatContentModules[itemId].load(chat_item)
457459

@@ -834,7 +836,7 @@ method onCommunityChannelDeletedOrChatLeft*(self: Module, chatId: string) =
834836
let activeChatId = self.controller.getActiveChatId()
835837
if chatId == activeChatId:
836838
self.setFirstChannelAsActive()
837-
839+
838840
self.updateParentBadgeNotifications()
839841

840842
proc refreshHiddenBecauseNotPermittedState(self: Module) =
@@ -1482,19 +1484,23 @@ method createOrEditCommunityTokenPermission*(self: Module, permissionId: string,
14821484
let tokenCriteriaJsonObj = tokenCriteriaJson.parseJson
14831485
for tokenCriteria in tokenCriteriaJsonObj:
14841486

1485-
let tokenKey = tokenCriteria{"key"}.getStr()
1487+
let communityTokenKey = tokenCriteria{"key"}.getStr()
1488+
var contractAddresses = initTable[int, string]()
14861489
var tokenCriteriaDto = tokenCriteria.toTokenCriteriaDto
1487-
if tokenCriteriaDto.`type` == TokenType.ERC20:
1488-
tokenCriteriaDto.decimals = self.controller.getTokenDecimals(tokenKey)
1489-
1490-
let contractAddresses = self.controller.getContractAddressesForToken(tokenKey)
1491-
if contractAddresses.len == 0 and tokenCriteriaDto.`type` != TokenType.ENS:
1492-
let communityId = self.controller.getMySectionId()
1493-
if permissionId == "":
1494-
self.onCommunityTokenPermissionCreationFailed(communityId)
1490+
1491+
if tokenCriteriaDto.`type` != TokenType.ENS:
1492+
let tokenKey = service_common_utils.communityKeyToTokenKey(communityTokenKey)
1493+
let token = self.controller.getTokenByKey(tokenKey)
1494+
if token.isNil and tokenCriteriaDto.`type` != TokenType.ENS:
1495+
error "unexisting token key: ", tokenKey, methodName="createOrEditCommunityTokenPermission"
1496+
let communityId = self.controller.getMySectionId()
1497+
if permissionId == "":
1498+
self.onCommunityTokenPermissionCreationFailed(communityId)
1499+
return
1500+
self.onCommunityTokenPermissionUpdateFailed(communityId)
14951501
return
1496-
self.onCommunityTokenPermissionUpdateFailed(communityId)
1497-
return
1502+
contractAddresses[token.chainId] = token.address
1503+
tokenCriteriaDto.decimals = token.decimals
14981504

14991505
tokenCriteriaDto.amountInWei = tokenCriteria{"amount"}.getStr
15001506
tokenCriteriaDto.contractAddresses = contractAddresses
@@ -1533,7 +1539,7 @@ method setChannelsPermissionsCheckOngoing*(self: Module, value: bool) =
15331539
for id, chat_item in self.view.chatsModel().items():
15341540
if self.view.chatsModel().getItemPermissionsRequired(chat_item.id):
15351541
self.view.chatsModel().updatePermissionsCheckOngoing(chat_item.id, true)
1536-
1542+
15371543
method onWaitingOnNewCommunityOwnerToConfirmRequestToRejoin*(self: Module) =
15381544
self.view.setWaitingOnNewCommunityOwnerToConfirmRequestToRejoin(true)
15391545

src/app/modules/main/communities/controller.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ proc requestCancelDiscordCommunityImport*(self: Controller, id: string) =
345345
proc requestCancelDiscordChannelImport*(self: Controller, discordChannelId: string) =
346346
self.communityService.requestCancelDiscordChannelImport(discordChannelId)
347347

348+
proc getAllKnownCommunityTokens*(self: Controller): var seq[TokenItem] =
349+
return self.tokenService.getAllCommunityTokens()
350+
348351
proc getCommunityTokens*(self: Controller, communityId: string): seq[CommunityTokenDto] =
349352
self.communityTokensService.getCommunityTokens(communityId)
350353

@@ -354,9 +357,6 @@ proc getAllCommunityTokens*(self: Controller): seq[CommunityTokenDto] =
354357
proc getNetworkByChainId*(self:Controller, chainId: int): NetworkItem =
355358
self.networksService.getNetworkByChainId(chainId)
356359

357-
proc getTokenBySymbolList*(self: Controller): seq[TokenBySymbolItem] =
358-
return self.tokenService.getTokenBySymbolList()
359-
360360
proc shareCommunityUrlWithChatKey*(self: Controller, communityId: string): string =
361361
return self.communityService.shareCommunityUrlWithChatKey(communityId)
362362

@@ -450,7 +450,7 @@ proc runSigningOnKeycard*(self: Controller, keyUid: string, path: string, dataTo
450450
var finalDataToSign = status_general.hashMessageForSigning(dataToSign)
451451
if finalDataToSign.startsWith("0x"):
452452
finalDataToSign = finalDataToSign[2..^1]
453-
453+
454454
if pin.len == 0:
455455
let data = SharedKeycarModuleSigningArgs(uniqueIdentifier: UNIQUE_COMMUNITIES_MODULE_SIGNING_IDENTIFIER,
456456
keyUid: keyUid,

src/app/modules/main/communities/module.nim

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ method requestCancelDiscordChannelImport*(self: Module, discordChannelId: string
513513
self.controller.requestCancelDiscordChannelImport(discordChannelId)
514514

515515
proc createCommunityTokenItem(self: Module, token: CommunityTokensMetadataDto, communityId: string, supply: string,
516-
infiniteSupply: bool, privilegesLevel: int): TokenListItem =
516+
infiniteSupply: bool, privilegesLevel: int): token_list_item.TokenListItem =
517517
let communityTokenDecimals = if token.tokenType == TokenType.ERC20: 18 else: 0
518518
let key = if token.tokenType == TokenType.ERC721: token.getContractIdFromFirstAddress() else: token.symbol
519519
result = initTokenListItem(
@@ -531,7 +531,7 @@ proc createCommunityTokenItem(self: Module, token: CommunityTokensMetadataDto, c
531531
)
532532

533533
proc buildCommunityTokenItemFallback(self: Module, communityTokens: seq[CommunityTokenDto],
534-
token: CommunityTokensMetadataDto, communityId: string): TokenListItem =
534+
token: CommunityTokensMetadataDto, communityId: string): token_list_item.TokenListItem =
535535
# Set fallback supply to infinite in case we don't have it
536536
var supply = "1"
537537
var infiniteSupply = true
@@ -545,8 +545,8 @@ proc buildCommunityTokenItemFallback(self: Module, communityTokens: seq[Communit
545545
return self.createCommunityTokenItem(token, communityId, supply, infiniteSupply, privilegesLevel)
546546

547547
proc buildTokensAndCollectiblesFromCommunities(self: Module, communities: seq[CommunityDto]) =
548-
var tokenListItems: seq[TokenListItem]
549-
var collectiblesListItems: seq[TokenListItem]
548+
var tokenListItems: seq[token_list_item.TokenListItem]
549+
var collectiblesListItems: seq[token_list_item.TokenListItem]
550550

551551
let communityTokens = self.controller.getAllCommunityTokens()
552552
for community in communities:
@@ -571,28 +571,25 @@ proc buildTokensAndCollectiblesFromAllCommunities(self: Module) =
571571
self.buildTokensAndCollectiblesFromCommunities(communities)
572572

573573
proc buildTokensAndCollectiblesFromWallet(self: Module) =
574-
var tokenListItems: seq[TokenListItem]
574+
var tokenListItems: seq[token_list_item.TokenListItem]
575575

576576
# Common ERC20 tokens
577577
let allNetworks = self.controller.getCurrentNetworksChainIds()
578-
let erc20Tokens = self.controller.getTokenBySymbolList().filter(t => (block:
579-
let filteredChains = t.addressPerChainId.filter(apC => allNetworks.contains(apc.chainId))
580-
return filteredChains.len != 0
581-
))
582-
for token in erc20Tokens:
583-
let communityTokens = self.controller.getCommunityTokens(token.communityId)
578+
let tokens = self.controller.getAllKnownCommunityTokens().filter(t => allNetworks.contains(t.chainId))
579+
for token in tokens:
580+
let communityTokens = self.controller.getCommunityTokens(token.communityData.id)
584581
var privilegesLevel = PrivilegesLevel.Community.int
585582
for communityToken in communityTokens:
586583
if communityToken.symbol == token.symbol:
587584
privilegesLevel = communityToken.privilegesLevel.int
588585
break
589586

590587
let tokenListItem = initTokenListItem(
591-
key = token.symbol,
588+
key = token.key,
592589
name = token.name,
593590
symbol = token.symbol,
594591
color = "",
595-
communityId = token.communityId,
592+
communityId = token.communityData.id,
596593
image = "",
597594
category = ord(TokenListItemCategory.General),
598595
decimals = token.decimals,

0 commit comments

Comments
 (0)