Skip to content

Commit

Permalink
fix(wallet): in app tx related notifications improvements
Browse files Browse the repository at this point in the history
Closes #16338
  • Loading branch information
saledjenic committed Nov 8, 2024
1 parent 9eaf4cc commit 504236a
Show file tree
Hide file tree
Showing 24 changed files with 559 additions and 293 deletions.
4 changes: 3 additions & 1 deletion src/app/core/signals/remote_signals/community.nim
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ proc fromEvent*(T: type CommunityMemberReevaluationStatusSignal, event: JsonNode
result = CommunityMemberReevaluationStatusSignal()
result.signalType = SignalType.MemberReevaluationStatus
result.communityId = event["event"]{"communityId"}.getStr()

result.status = CommunityMemberReevaluationStatus.None
var statusInt: int
if (event["event"].getProp("status", statusInt) and (statusInt >= ord(low(CommunityMemberReevaluationStatus)) and
Expand Down Expand Up @@ -275,6 +275,7 @@ proc downloadingHistoryArchivesFinishedFromEvent*(T: type HistoryArchivesSignal,

proc fromEvent*(T: type CommunityTokenTransactionStatusChangedSignal, event: JsonNode): CommunityTokenTransactionStatusChangedSignal =
result = CommunityTokenTransactionStatusChangedSignal()
result.signalType = SignalType.CommunityTokenTransactionStatusChanged
result.transactionType = event["event"]{"transactionType"}.getStr()
result.success = event["event"]{"success"}.getBool()
result.hash = event["event"]{"hash"}.getStr()
Expand All @@ -289,6 +290,7 @@ proc fromEvent*(T: type CommunityTokenTransactionStatusChangedSignal, event: Jso

proc fromEvent*(T: type CommunityTokenActionSignal, event: JsonNode): CommunityTokenActionSignal =
result = CommunityTokenActionSignal()
result.signalType = SignalType.CommunityTokenAction
result.actionType = CommunityTokenActionType.Unknown
if event["event"].hasKey("communityToken"):
result.communityToken = toCommunityTokenDto(event["event"]{"communityToken"})
Expand Down
4 changes: 4 additions & 0 deletions src/app/core/signals/remote_signals/connector.nim
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ type ConnectorRevokeDAppPermissionSignal* = ref object of Signal

proc fromEvent*(T: type ConnectorSendRequestAccountsSignal, event: JsonNode): ConnectorSendRequestAccountsSignal =
result = ConnectorSendRequestAccountsSignal()
result.signalType = SignalType.ConnectorSendRequestAccounts
result.url = event["event"]{"url"}.getStr()
result.name = event["event"]{"name"}.getStr()
result.iconUrl = event["event"]{"iconUrl"}.getStr()
result.requestId = event["event"]{"requestId"}.getStr()

proc fromEvent*(T: type ConnectorSendTransactionSignal, event: JsonNode): ConnectorSendTransactionSignal =
result = ConnectorSendTransactionSignal()
result.signalType = SignalType.ConnectorSendTransaction
result.url = event["event"]{"url"}.getStr()
result.name = event["event"]{"name"}.getStr()
result.iconUrl = event["event"]{"iconUrl"}.getStr()
Expand All @@ -45,12 +47,14 @@ proc fromEvent*(T: type ConnectorSendTransactionSignal, event: JsonNode): Connec

proc fromEvent*(T: type ConnectorGrantDAppPermissionSignal, event: JsonNode): ConnectorGrantDAppPermissionSignal =
result = ConnectorGrantDAppPermissionSignal()
result.signalType = SignalType.ConnectorGrantDAppPermission
result.url = event["event"]{"url"}.getStr()
result.name = event["event"]{"name"}.getStr()
result.iconUrl = event["event"]{"iconUrl"}.getStr()

proc fromEvent*(T: type ConnectorRevokeDAppPermissionSignal, event: JsonNode): ConnectorRevokeDAppPermissionSignal =
result = ConnectorRevokeDAppPermissionSignal()
result.signalType = SignalType.ConnectorRevokeDAppPermission
result.url = event["event"]{"url"}.getStr()
result.name = event["event"]{"name"}.getStr()
result.iconUrl = event["event"]{"iconUrl"}.getStr()
1 change: 1 addition & 0 deletions src/app/core/signals/remote_signals/messages.nim
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ proc fromEvent*(T: type MessageDeliveredSignal, event: JsonNode): MessageDeliver

proc fromEvent*(T: type MessageSignal, event: JsonNode): MessageSignal =
var signal:MessageSignal = MessageSignal()
signal.signalType = SignalType.Message
signal.messages = @[]
signal.contacts = @[]

Expand Down
3 changes: 2 additions & 1 deletion src/app/core/signals/remote_signals/node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ type NodeSignal* = ref object of Signal
account*: AccountDto
settings*: SettingsDto

proc fromEvent*(T: type NodeSignal, event: JsonNode): NodeSignal =
proc fromEvent*(T: type NodeSignal, signalType: SignalType, event: JsonNode): NodeSignal =
result = NodeSignal()
result.signalType = signalType

if not event.contains("event") or event["event"].kind == JNull:
return
Expand Down
1 change: 1 addition & 0 deletions src/app/core/signals/remote_signals/pairing.nim
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type LocalPairingSignal* = ref object of Signal

proc fromEvent*(T: type LocalPairingSignal, event: JsonNode): LocalPairingSignal =
result = LocalPairingSignal()
result.signalType = SignalType.LocalPairing
let e = event["event"]
if e.contains("type"):
result.eventType = e["type"].getStr().parse()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type WakuBackedUpKeypairSignal* = ref object of Signal

proc fromEvent*(T: type WakuBackedUpKeypairSignal, event: JsonNode): WakuBackedUpKeypairSignal =
result = WakuBackedUpKeypairSignal()
result.signalType = SignalType.WakuBackedUpKeypair

let e = event["event"]
if e.contains("backedUpKeypair"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ type WakuBackedUpProfileSignal* = ref object of Signal

proc fromEvent*(T: type WakuBackedUpProfileSignal, event: JsonNode): WakuBackedUpProfileSignal =
result = WakuBackedUpProfileSignal()

result.signalType = SignalType.WakuBackedUpProfile

let e = event["event"]
if e.contains("backedUpProfile"):
result.backedUpProfile = e["backedUpProfile"].toWakuBackedUpProfileDto()
result.backedUpProfile = e["backedUpProfile"].toWakuBackedUpProfileDto()
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ type WakuBackedUpSettingsSignal* = ref object of Signal

proc fromEvent*(T: type WakuBackedUpSettingsSignal, event: JsonNode): WakuBackedUpSettingsSignal =
result = WakuBackedUpSettingsSignal()

result.signalType = SignalType.WakuBackedUpSettings

let e = event["event"]
if e.contains("backedUpSettings"):
result.backedUpSettings = e["backedUpSettings"].toSettingsDto()
result.backedUpSettings = e["backedUpSettings"].toSettingsDto()
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type WakuBackedUpWatchOnlyAccountSignal* = ref object of Signal

proc fromEvent*(T: type WakuBackedUpWatchOnlyAccountSignal, event: JsonNode): WakuBackedUpWatchOnlyAccountSignal =
result = WakuBackedUpWatchOnlyAccountSignal()
result.signalType = SignalType.WakuBackedUpWatchOnlyAccount

let e = event["event"]
if e.contains("backedUpWatchOnlyAccount"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ import base

type WakuFetchingBackupProgress* = object
dataNumber*: int
totalNumber*: int
totalNumber*: int

type WakuFetchingBackupProgressSignal* = ref object of Signal
clock*: uint64
fetchingBackupProgress*: Table[string, WakuFetchingBackupProgress]

proc fromEvent*(T: type WakuFetchingBackupProgressSignal, event: JsonNode): WakuFetchingBackupProgressSignal =
result = WakuFetchingBackupProgressSignal()
result.signalType = SignalType.WakuFetchingBackupProgress
result.fetchingBackupProgress = initTable[string, WakuFetchingBackupProgress]()

let e = event["event"]
Expand Down
21 changes: 16 additions & 5 deletions src/app/core/signals/remote_signals/wallet.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import signal_type
import app_service/service/transaction/dtoV2
import app_service/service/transaction/router_transactions_dto

const SignTransactionsEventType* = "sing-transactions"
const
EventPendingTransactionUpdate* = "pending-transaction-update"
EventPendingTransactionStatusChanged* = "pending-transaction-status-changed"

type WalletSignal* = ref object of Signal
content*: string
Expand All @@ -33,7 +35,7 @@ type WalletSignal* = ref object of Signal

proc fromEvent*(T: type WalletSignal, signalType: SignalType, jsonSignal: JsonNode): WalletSignal =
result = WalletSignal()
result.signalType = SignalType.Wallet
result.signalType = signalType
let event = jsonSignal["event"]
if event.kind == JNull:
return
Expand All @@ -52,6 +54,18 @@ proc fromEvent*(T: type WalletSignal, signalType: SignalType, jsonSignal: JsonNo
const requestIdName = "requestId"
if event.contains(requestIdName):
result.requestId = some(event[requestIdName].getInt())

## handling tx status change
if result.eventType == EventPendingTransactionStatusChanged:
result.signalType = SignalType.WalletTransactionStatusChanged
if result.message.len == 0:
return
var statusChangedPayload: JsonNode
try:
statusChangedPayload = result.message.parseJson
except CatchableError:
return
result.transactionStatusChange = toTransactionStatusChange(statusChangedPayload)
return
if signalType == SignalType.WalletSignTransactions:
if event.kind != JArray:
Expand All @@ -73,9 +87,6 @@ proc fromEvent*(T: type WalletSignal, signalType: SignalType, jsonSignal: JsonNo
result.routerTransactionsSendingDetails = toSendDetailsDto(event)
return
if signalType == SignalType.WalletTransactionStatusChanged:
if event.kind != JObject:
return
result.transactionStatusChange = toTransactionStatusChange(event)
return
if signalType == SignalType.WalletSuggestedRoutes:
try:
Expand Down
2 changes: 2 additions & 0 deletions src/app/core/signals/remote_signals/whisper_filter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ proc toFilter(jsonMsg: JsonNode): Filter =
)

proc fromEvent*(T: type WhisperFilterSignal, event: JsonNode): WhisperFilterSignal =
result = WhisperFilterSignal()
result.signalType = SignalType.WhisperFilterAdded
if event["event"]{"filters"} != nil:
for jsonMsg in event["event"]["filters"]:
result.filters.add(jsonMsg.toFilter)
7 changes: 3 additions & 4 deletions src/app/core/signals/signals_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ QtObject:
SignalType.NodeStarted,
SignalType.NodeStopped,
SignalType.NodeLogin:
NodeSignal.fromEvent(jsonSignal)
NodeSignal.fromEvent(signalType, jsonSignal)
of SignalType.PeerStats: PeerStatsSignal.fromEvent(jsonSignal)
of SignalType.DiscoverySummary: DiscoverySummarySignal.fromEvent(jsonSignal)
of SignalType.MailserverRequestCompleted: MailserverRequestCompletedSignal.fromEvent(jsonSignal)
Expand Down Expand Up @@ -144,6 +144,5 @@ QtObject:
of SignalType.ConnectorSendTransaction: ConnectorSendTransactionSignal.fromEvent(jsonSignal)
of SignalType.ConnectorGrantDAppPermission: ConnectorGrantDAppPermissionSignal.fromEvent(jsonSignal)
of SignalType.ConnectorRevokeDAppPermission: ConnectorRevokeDAppPermissionSignal.fromEvent(jsonSignal)
else: Signal()

result.signalType = signalType
else:
Signal(signalType: signalType)
Loading

0 comments on commit 504236a

Please sign in to comment.