Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/deep link 16345 with unfurl #16554

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app/modules/main/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1646,6 +1646,8 @@ method activateStatusDeepLink*[T](self: Module[T], statusDeepLink: string) =
self.onStatusUrlRequested(StatusUrlAction.DisplayUserProfile, communityId="", channelId="", url="",
urlData.contact.publicKey, urlData.community.shard)
return
if urlData.transaction.txType >= 0:
self.view.emitShowTransactionModal(urlData.transaction.txType, urlData.transaction.asset, urlData.transaction.amount, urlData.transaction.address, urlData.transaction.chainId, urlData.transaction.toAsset)

method onDeactivateChatLoader*[T](self: Module[T], sectionId: string, chatId: string) =
if (sectionId.len > 0 and self.chatSectionModules.contains(sectionId)):
Expand Down
4 changes: 4 additions & 0 deletions src/app/modules/main/shared_urls/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ proc parseContactSharedUrl*(self: Controller, url: string): ContactUrlDataDto =

proc parseSharedUrl*(self: Controller, url: string): UrlDataDto =
return self.sharedUrlsService.parseSharedUrl(url)

proc parseTransactionSharedUrl*(self: Controller, url: string): TransactionUrlDataDto =
let data = self.sharedUrlsService.parseSharedUrl(url)
return data.transaction
3 changes: 3 additions & 0 deletions src/app/modules/main/shared_urls/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ method parseContactSharedUrl*(self: AccessInterface, url: string): string {.base
method parseSharedUrl*(self: AccessInterface, url: string): UrlDataDto {.base.} =
raise newException(ValueError, "No implementation available")

method parseTransactionSharedUrl*(self: AccessInterface, url: string): string {.base.} =
raise newException(ValueError, "No implementation available")

# This way (using concepts) is used only for the modules managed by AppController
type
DelegateInterface* = concept c
Expand Down
4 changes: 4 additions & 0 deletions src/app/modules/main/shared_urls/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ method parseCommunityChannelSharedUrl*(self: Module, url: string): string =
method parseContactSharedUrl*(self: Module, url: string): string =
let contactData = self.controller.parseContactSharedUrl(url)
return $contactData

method parseTransactionSharedUrl*(self: Module, url: string): string =
let transactionData = self.controller.parseTransactionSharedUrl(url)
return $transactionData
5 changes: 4 additions & 1 deletion src/app/modules/main/shared_urls/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ QtObject:
return self.delegate.parseCommunityChannelSharedUrl(url)

proc parseContactSharedUrl*(self: View, url: string): string {.slot.} =
return self.delegate.parseContactSharedUrl(url)
return self.delegate.parseContactSharedUrl(url)

proc parseTransactionSharedUrl*(self: View, url: string): string {.slot.} =
return self.delegate.parseTransactionSharedUrl(url)
5 changes: 5 additions & 0 deletions src/app/modules/main/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,8 @@ QtObject:

proc stopTokenHoldersManagement*(self: View) {.slot.} =
self.delegate.stopTokenHoldersManagement()

proc showTransactionModal*(self: View, txType: int, asset: string, amount: string, address: string, chainId: int, toAsset: string) {.signal.}
proc emitShowTransactionModal*(self: View, txType: int, asset: string, amount: string, address: string, chainId: int, toAsset: string) =
self.showTransactionModal(txType, asset, amount, address, chainId, toAsset)

4 changes: 4 additions & 0 deletions src/app/modules/main/wallet_section/send/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import app_service/service/currency/service as currency_service
import app_service/service/currency/dto as currency_dto
import app_service/service/keycard/service as keycard_service
import app_service/service/network/network_item
import app_service/service/shared_urls/dto/url_data as shared_urls_dto

import app/modules/shared_modules/keycard_popup/io_interface as keycard_shared_module
import app/modules/shared/wallet_utils
Expand Down Expand Up @@ -137,6 +138,9 @@ proc signMessage*(self: Controller, address: string, hashedPassword: string, has
proc sendRouterTransactionsWithSignatures*(self: Controller, uuid: string, signatures: TransactionsSignatures): string =
return self.transactionService.sendRouterTransactionsWithSignatures(uuid, signatures)

proc shareTransactionURL*(self: Controller, urlData: shared_urls_dto.TransactionURLDataDto): string =
return self.transactionService.shareTransactionURL(urlData)

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

Expand Down
4 changes: 4 additions & 0 deletions src/app/modules/main/wallet_section/send/io_interface.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Tables
import app/modules/shared_models/currency_amount
import app_service/service/transaction/dto
import app_service/service/transaction/router_transactions_dto
import app_service/service/shared_urls/dto/url_data
import app_service/service/network/network_item
import app/modules/shared_models/collectibles_model as collectibles
from app_service/service/keycard/service import KeycardEvent
Expand Down Expand Up @@ -90,4 +91,7 @@ method getNetworkItem*(self: AccessInterface, chainId: int): NetworkItem {.base.
raise newException(ValueError, "No implementation available")

method getNetworkChainId*(self: AccessInterface, shortName: string): int {.base.} =
raise newException(ValueError, "No implementation available")

method shareTransactionURL*(self: AccessInterface, urlData: TransactionURLDataDto): string {.base.} =
raise newException(ValueError, "No implementation available")
4 changes: 4 additions & 0 deletions src/app/modules/main/wallet_section/send/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import app_service/service/transaction/service as transaction_service
import app_service/service/keycard/service as keycard_service
import app_service/service/keycard/constants as keycard_constants
import app_service/service/transaction/dto
import app_service/service/shared_urls/dto/url_data as shared_urls_dto
import app/modules/shared_models/currency_amount
import app_service/service/network/network_item as network_service_item

Expand Down Expand Up @@ -404,3 +405,6 @@ method splitAndFormatAddressPrefix*(self: Module, text : string, updateInStore:

method transactionSendingComplete*(self: Module, txHash: string, status: string) =
self.view.sendtransactionSendingCompleteSignal(txHash, status)

method shareTransactionURL*(self: Module, urlData: shared_urls_dto.TransactionURLDataDto): string =
return self.controller.shareTransactionURL(urlData)
11 changes: 11 additions & 0 deletions src/app/modules/main/wallet_section/send/view.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import NimQml, Tables, json, sequtils, strutils, stint, chronicles
import ./io_interface, ./network_route_model, ./network_route_item, ./suggested_route_item, ./transaction_routes
import app_service/service/network/service as network_service
import app_service/service/transaction/dto as transaction_dto
import app_service/service/shared_urls/dto/url_data as shared_urls_dto

import app_service/common/utils as common_utils
import app_service/service/eth/utils as eth_utils
Expand Down Expand Up @@ -295,6 +296,16 @@ QtObject:
parseChainIds(disabledToChainIDs),
lockedInAmountsTable)

proc shareTransactionURL*(self: View, txType: int, asset: string, amount: string, address: string, chainId: int, toAsset: string): string {.slot.} =
return self.delegate.shareTransactionURL(shared_urls_dto.TransactionURLDataDto(
txType: txType,
asset: asset,
amount: amount,
address: address,
chainId: chainId,
toAsset: toAsset
))

proc transactionSendingComplete*(self: View, txHash: string, status: string) {.signal.}
proc sendtransactionSendingCompleteSignal*(self: View, txHash: string, status: string) =
self.transactionSendingComplete(txHash, status)
Expand Down
7 changes: 7 additions & 0 deletions src/app/modules/shared_models/link_preview_model.nim
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type
StatusCommunityChannelCommunityPreview
StatusCommunityChannelCommunityPreviewIcon
StatusCommunityChannelCommunityPreviewBanner
# Status transaction
StatusTransactionPreview

QtObject:
type
Expand Down Expand Up @@ -105,6 +107,8 @@ QtObject:
ModelRole.StatusCommunityChannelCommunityPreview.int:"statusCommunityChannelCommunityPreview",
ModelRole.StatusCommunityChannelCommunityPreviewIcon.int:"statusCommunityChannelCommunityPreviewIcon",
ModelRole.StatusCommunityChannelCommunityPreviewBanner.int:"statusCommunityChannelCommunityPreviewBanner",
# Transaction
ModelRole.StatusTransactionPreview.int:"statusTransactionPreview",
}.toTable

method data(self: Model, index: QModelIndex, role: int): QVariant =
Expand Down Expand Up @@ -165,6 +169,9 @@ QtObject:
of ModelRole.StatusCommunityChannelCommunityPreviewBanner:
if (let community = item.linkPreview.getChannelCommunity(); community) != nil:
result = newQVariant(community.getBanner())
of ModelRole.StatusTransactionPreview:
if item.linkPreview.statusTransactionPreview != nil:
result = newQVariant(item.linkPreview.statusTransactionPreview)
else:
result = newQVariant()

Expand Down
23 changes: 20 additions & 3 deletions src/app_service/service/message/dto/link_preview.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json, stew/shims/strformat, tables
import ./status_link_preview, ./standard_link_preview
import ./status_contact_link_preview, ./status_community_link_preview, ./status_community_channel_link_preview
import ./status_contact_link_preview, ./status_community_link_preview, ./status_community_channel_link_preview, ./status_transaction_link_preview
import ../../contacts/dto/contact_details
import ../../community/dto/community
include ../../../common/json_utils
Expand All @@ -13,6 +13,7 @@ type
StatusContactPreview
StatusCommunityPreview
StatusCommunityChannelPreview
StatusTransactionPreview

LinkPreview* = ref object
url*: string
Expand All @@ -21,6 +22,7 @@ type
statusContactPreview*: StatusContactLinkPreview
statusCommunityPreview*: StatusCommunityLinkPreview
statusCommunityChannelPreview*: StatusCommunityChannelLinkPreview
statusTransactionPreview*: StatusTransactionLinkPreview

proc delete*(self: LinkPreview) =
if self.standardPreview != nil:
Expand All @@ -31,6 +33,8 @@ proc delete*(self: LinkPreview) =
self.statusCommunityPreview.delete
if self.statusCommunityChannelPreview != nil:
self.statusCommunityChannelPreview.delete
if self.statusTransactionPreview != nil:
self.statusTransactionPreview.delete

proc initLinkPreview*(url: string): LinkPreview =
result = LinkPreview()
Expand All @@ -57,19 +61,24 @@ proc toLinkPreview*(jsonObj: JsonNode, standard: bool): LinkPreview =
elif jsonObj.getProp("channel", node):
result.previewType = PreviewType.StatusCommunityChannelPreview
result.statusCommunityChannelPreview = toStatusCommunityChannelLinkPreview(node)
elif jsonObj.getProp("transaction", node):
result.previewType = PreviewType.StatusTransactionPreview
result.statusTransactionPreview = toStatusTransactionLinkPreview(node)

proc `$`*(self: LinkPreview): string =
let standardPreview = if self.standardPreview != nil: $self.standardPreview else: ""
let contactPreview = if self.statusContactPreview != nil: $self.statusContactPreview else: ""
let communityPreview = if self.statusCommunityPreview != nil: $self.statusCommunityPreview else: ""
let channelPreview = if self.statusCommunityChannelPreview != nil: $self.statusCommunityChannelPreview else: ""
let transactionPreview = if self.statusTransactionPreview != nil: $self.statusTransactionPreview else: ""
result = fmt"""LinkPreview(
url: {self.url},
previewType: {self.previewType},
standardPreview: {standardPreview},
contactPreview: {contactPreview},
communityPreview: {communityPreview},
channelPreview: {channelPreview}
channelPreview: {channelPreview},
transactionPreview: {transactionPreview}
)"""

proc `%`*(self: LinkPreview): JsonNode =
Expand All @@ -78,7 +87,8 @@ proc `%`*(self: LinkPreview): JsonNode =
"standardPreview": if self.standardPreview != nil: %self.standardPreview else: newJNull(),
"contactPreview": if self.statusContactPreview != nil: %self.statusContactPreview else: newJNull(),
"communityPreview": if self.statusCommunityPreview != nil: %self.statusCommunityPreview else: newJNull(),
"channelPreview": if self.statusCommunityChannelPreview != nil: %self.statusCommunityChannelPreview else: newJNull()
"channelPreview": if self.statusCommunityChannelPreview != nil: %self.statusCommunityChannelPreview else: newJNull(),
"transactionPreview": if self.statusTransactionPreview != nil: %self.statusTransactionPreview else: newJNull()
}

proc empty*(self: LinkPreview): bool =
Expand All @@ -91,6 +101,8 @@ proc empty*(self: LinkPreview): bool =
return self.statusCommunityPreview == nil or self.statusCommunityPreview.empty()
of PreviewType.StatusCommunityChannelPreview:
return self.statusCommunityChannelPreview == nil or self.statusCommunityChannelPreview.empty()
of PreviewType.StatusTransactionPreview:
return self.statusTransactionPreview == nil or self.statusTransactionPreview.empty()
else:
return true

Expand Down Expand Up @@ -119,6 +131,11 @@ proc extractLinkPreviewsLists*(input: seq[LinkPreview]): (seq[StandardLinkPrevie
statusLinkPreview.url = preview.url
statusLinkPreview.channel = preview.statusCommunityChannelPreview
status.add(statusLinkPreview)
of PreviewType.StatusTransactionPreview:
let statusLinkPreview = StatusLinkPreview()
statusLinkPreview.url = preview.url
statusLinkPreview.transaction = preview.statusTransactionPreview
status.add(statusLinkPreview)
else:
discard

Expand Down
8 changes: 8 additions & 0 deletions src/app_service/service/message/dto/status_link_preview.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import json, chronicles
import status_contact_link_preview
import status_community_link_preview
import status_community_channel_link_preview
import status_transaction_link_preview
include ../../../common/json_utils


Expand All @@ -10,6 +11,7 @@ type StatusLinkPreview* = ref object
contact*: StatusContactLinkPreview
community*: StatusCommunityLinkPreview
channel*: StatusCommunityChannelLinkPreview
transaction*: StatusTransactionLinkPreview

proc toStatusLinkPreview*(jsonObj: JsonNode): StatusLinkPreview =
result = StatusLinkPreview()
Expand All @@ -27,6 +29,10 @@ proc toStatusLinkPreview*(jsonObj: JsonNode): StatusLinkPreview =
if jsonObj.getProp("channel", channel):
result.channel = toStatusCommunityChannelLinkPreview(contact)

var transaction: JsonNode
if jsonObj.getProp("transaction", transaction):
result.transaction = toStatusTransactionLinkPreview(transaction)

proc `%`*(self: StatusLinkPreview): JsonNode =
var obj = %*{
"url": self.url
Expand All @@ -37,4 +43,6 @@ proc `%`*(self: StatusLinkPreview): JsonNode =
obj["community"] = %*self.community
if self.channel != nil:
obj["channel"] = %*self.channel
if self.transaction != nil:
obj["transaction"] = %*self.transaction
return obj
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import json, stew/shims/strformat, NimQml, chronicles

include ../../../common/json_utils

QtObject:
type StatusTransactionLinkPreview* = ref object of QObject
txType: int
amount: string
asset: string
toAsset: string
address: string
chainId: int

proc setup*(self: StatusTransactionLinkPreview) =
self.QObject.setup()

proc delete*(self: StatusTransactionLinkPreview) =
self.QObject.delete()

proc newStatusTransactionLinkPreview*(txType: int, amount: string, asset: string, toAsset: string, address: string, chainId: int): StatusTransactionLinkPreview =
new(result, delete)
result.setup()
result.txType = txType
result.amount = amount
result.asset = asset
result.toAsset = toAsset
result.address = address
result.chainId = chainId

proc txTypeChanged*(self: StatusTransactionLinkPreview) {.signal.}
proc getTxType*(self: StatusTransactionLinkPreview): int {.slot.} =
result = self.txType
QtProperty[int] txType:
read = getTxType
notify = txTypeChanged

proc amountChanged*(self: StatusTransactionLinkPreview) {.signal.}
proc getAmount*(self: StatusTransactionLinkPreview): string {.slot.} =
result = self.amount
QtProperty[string] amount:
read = getAmount
notify = amountChanged

proc assetChanged*(self: StatusTransactionLinkPreview) {.signal.}
proc getAsset*(self: StatusTransactionLinkPreview): string {.slot.} =
result = self.asset
QtProperty[string] asset:
read = getAsset
notify = assetChanged

proc toAssetChanged*(self: StatusTransactionLinkPreview) {.signal.}
proc getToAsset*(self: StatusTransactionLinkPreview): string {.slot.} =
result = self.toAsset
QtProperty[string] toAsset:
read = getToAsset
notify = toAssetChanged

proc addressChanged*(self: StatusTransactionLinkPreview) {.signal.}
proc getAddress*(self: StatusTransactionLinkPreview): string {.slot.} =
result = self.address
QtProperty[string] address:
read = getAddress
notify = addressChanged

proc chainIdChanged*(self: StatusTransactionLinkPreview) {.signal.}
proc getChainId*(self: StatusTransactionLinkPreview): int {.slot.} =
result = self.chainId
QtProperty[int] chainId:
read = getChainId
notify = chainIdChanged

proc toStatusTransactionLinkPreview*(jsonObj: JsonNode): StatusTransactionLinkPreview =
var txType: int
var amount: string
var asset: string
var toAsset: string
var address: string
var chainId: int

discard jsonObj.getProp("txType", txType)
discard jsonObj.getProp("amount", amount)
discard jsonObj.getProp("asset", asset)
discard jsonObj.getProp("toAsset", toAsset)
discard jsonObj.getProp("address", address)
discard jsonObj.getProp("chainId", chainId)

result = newStatusTransactionLinkPreview(txType, amount, asset, toAsset, address, chainId)

proc `$`*(self: StatusTransactionLinkPreview): string =
result = fmt"""StatusTransactionLinkPreview(
txType: {self.txType},
amount: {self.amount},
asset: {self.asset},
toAsset: {self.toAsset},
address: {self.address},
chainId: {self.chainId}
)"""

proc `%`*(self: StatusTransactionLinkPreview): JsonNode =
return %* {
"txType": self.txType,
"amount": self.amount,
"asset": self.asset,
"toAsset": self.toAsset,
"address": self.address,
"chainId": self.chainId
}

proc empty*(self: StatusTransactionLinkPreview): bool =
return self.amount.len == 0 and self.asset.len == 0 and self.toAsset.len == 0 and self.address.len == 0
Loading