Skip to content
Merged
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: 1 addition & 1 deletion ci/Jenkinsfile.linux
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pipeline {
job: 'status-desktop/e2e/prs',
wait: false,
parameters: jenkins.mapToParams([
GIT_REF: env.GIT_COMMIT,
GIT_REF: env.CHANGE_BRANCH ?: env.BRANCH_NAME,
BUILD_SOURCE: env.JOB_NAME,
]),
)
Expand Down
2 changes: 1 addition & 1 deletion ci/Jenkinsfile.windows
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ pipeline {
job: 'status-desktop/e2e/prs-windows',
wait: false,
parameters: jenkins.mapToParams([
GIT_REF: env.GIT_COMMIT,
GIT_REF: env.CHANGE_BRANCH ?: env.BRANCH_NAME,
BUILD_SOURCE: env.JOB_NAME,
]),
)
Expand Down
12 changes: 11 additions & 1 deletion src/app/core/signals/remote_signals/connector.nim
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ type ConnectorSignSignal* = ref object of Signal
address*: string
signMethod*: string

type ConnectorDAppChainIdSwitchedSignal* = ref object of Signal
url*: string
chainId*: string

proc fromEvent*(T: type ConnectorSendRequestAccountsSignal, event: JsonNode): ConnectorSendRequestAccountsSignal =
result = ConnectorSendRequestAccountsSignal()
result.signalType = SignalType.ConnectorSendRequestAccounts
Expand Down Expand Up @@ -81,4 +85,10 @@ proc fromEvent*(T: type ConnectorSignSignal, event: JsonNode): ConnectorSignSign
result.requestId = event["event"]{"requestId"}.getStr()
result.challenge = event["event"]{"challenge"}.getStr()
result.address = event["event"]{"address"}.getStr()
result.signMethod = event["event"]{"method"}.getStr()
result.signMethod = event["event"]{"method"}.getStr()

proc fromEvent*(T: type ConnectorDAppChainIdSwitchedSignal, event: JsonNode): ConnectorDAppChainIdSwitchedSignal =
result = ConnectorDAppChainIdSwitchedSignal()
result.signalType = SignalType.ConnectorDAppChainIdSwitched
result.url = event["event"]{"url"}.getStr()
result.chainId = event["event"]{"chainId"}.getStr()
1 change: 1 addition & 0 deletions src/app/core/signals/remote_signals/signal_type.nim
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type SignalType* {.pure.} = enum
ConnectorGrantDAppPermission = "connector.dAppPermissionGranted"
ConnectorRevokeDAppPermission = "connector.dAppPermissionRevoked"
ConnectorSign = "connector.Sign"
ConnectorDAppChainIdSwitched = "connector.dAppChainIdSwitched"
LocalMessageBackupDone = "local.message.backup.done"
Unknown

Expand Down
1 change: 1 addition & 0 deletions src/app/core/signals/signals_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ QtObject:
of SignalType.ConnectorGrantDAppPermission: ConnectorGrantDAppPermissionSignal.fromEvent(jsonSignal)
of SignalType.ConnectorRevokeDAppPermission: ConnectorRevokeDAppPermissionSignal.fromEvent(jsonSignal)
of SignalType.ConnectorSign: ConnectorSignSignal.fromEvent(jsonSignal)
of SignalType.ConnectorDAppChainIdSwitched: ConnectorDAppChainIdSwitchedSignal.fromEvent(jsonSignal)
# networks
of SignalType.NetworksBlockchainHealthChanged: NetworksBlockchainHealthChangedSignal.fromEvent(jsonSignal)
else:
Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/main/wallet_section/module.nim
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ proc newModule*(
result.walletConnectService = wc_service.newService(result.events, result.threadpool, settingsService, transactionService, keycardService)
result.walletConnectController = wc_controller.newController(result.walletConnectService, walletAccountService, result.events)

result.dappsConnectorService = connector_service.newService(result.events)
result.dappsConnectorService = connector_service.newService(result.events, result.threadpool)
result.dappsConnectorController = connector_controller.newController(result.dappsConnectorService, result.events)
result.view = newView(result, result.activityController, result.tmpActivityControllers, result.collectibleDetailsController, result.walletConnectController, result.dappsConnectorController)
result.viewVariant = newQVariant(result.view)
Expand Down
24 changes: 24 additions & 0 deletions src/app/modules/shared_modules/connector/controller.nim
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const SIGNAL_CONNECTOR_EVENT_CONNECTOR_SEND_TRANSACTION* = "ConnectorSendTransac
const SIGNAL_CONNECTOR_GRANT_DAPP_PERMISSION* = "ConnectorGrantDAppPermission"
const SIGNAL_CONNECTOR_REVOKE_DAPP_PERMISSION* = "ConnectorRevokeDAppPermission"
const SIGNAL_CONNECTOR_SIGN* = "ConnectorSign"
const SIGNAL_CONNECTOR_CALL_RPC_RESULT* = "ConnectorCallRPCResult"
const SIGNAL_CONNECTOR_DAPP_CHAIN_ID_SWITCHED* = "ConnectorDAppChainIdSwitched"

logScope:
topics = "connector-controller"
Expand All @@ -28,6 +30,8 @@ QtObject:
proc emitDisconnected*(self: Controller, payload: string)
proc emitSendTransaction*(self: Controller, requestId: string, payload: string)
proc emitSign*(self: Controller, requestId: string, payload: string)
proc emitConnectorCallRPCResult*(self: Controller, requestId: int, payload: string)
proc emitChainIdSwitched*(self: Controller, payload: string)

proc newController*(service: connector_service.Service, events: EventEmitter): Controller =
new(result, delete)
Expand Down Expand Up @@ -98,6 +102,18 @@ QtObject:

controller.emitSign(params.requestId, dappInfo.toJson())

result.events.on(SIGNAL_CONNECTOR_CALL_RPC_RESULT) do(e: Args):
let params = connector_service.ConnectorCallRPCResultArgs(e)
controller.emitConnectorCallRPCResult(params.requestId, params.payload)

result.events.on(SIGNAL_CONNECTOR_DAPP_CHAIN_ID_SWITCHED) do(e: Args):
let params = ConnectorDAppChainIdSwitchedSignal(e)
let chainInfo = %*{
"url": params.url,
"chainId": params.chainId
}
controller.emitChainIdSwitched(chainInfo.toJson())

result.QObject.setup

proc connectRequested*(self: Controller, requestId: string, payload: string) {.signal.}
Expand All @@ -108,6 +124,8 @@ QtObject:
proc sign(self: Controller, requestId: string, payload: string) {.signal.}
proc approveConnectResponse*(self: Controller, payload: string, error: bool) {.signal.}
proc rejectConnectResponse*(self: Controller, payload: string, error: bool) {.signal.}
proc connectorCallRPCResult*(self: Controller, requestId: int, payload: string) {.signal.}
proc chainIdSwitched*(self: Controller, payload: string) {.signal.}

proc approveTransactionResponse*(self: Controller, topic: string, requestId: string, error: bool) {.signal.}
proc rejectTransactionResponse*(self: Controller, topic: string, requestId: string, error: bool) {.signal.}
Expand All @@ -124,6 +142,10 @@ QtObject:
self.sendTransaction(requestId, payload)
proc emitSign*(self: Controller, requestId: string, payload: string) =
self.sign(requestId, payload)
proc emitConnectorCallRPCResult*(self: Controller, requestId: int, payload: string) =
self.connectorCallRPCResult(requestId, payload)
proc emitChainIdSwitched*(self: Controller, payload: string) =
self.chainIdSwitched(payload)

proc parseSingleUInt(chainIDsString: string): uint =
try:
Expand Down Expand Up @@ -175,3 +197,5 @@ QtObject:
proc delete*(self: Controller) =
self.QObject.delete

proc connectorCallRPC*(self: Controller, requestId: int, message: string) {.slot.} =
self.service.connectorCallRPC(requestId, message)
30 changes: 30 additions & 0 deletions src/app_service/service/connector/async_tasks.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import json, json_serialization, chronicles
import backend/connector as status_go
import app/core/tasks/qt

logScope:
topics = "connector-async-tasks"

type
ConnectorCallRPCTaskArg* = ref object of QObjectTaskArg
requestId*: int
message*: string

proc connectorCallRPCTask*(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[ConnectorCallRPCTaskArg](argEncoded)
try:
let rpcResponse = status_go.connectorCallRPC(arg.message)
let responseJson = %* {
"requestId": arg.requestId,
"result": $rpcResponse.result,
"error": if rpcResponse.error.isNil: "" else: rpcResponse.error.message
}

arg.finish(responseJson)
except Exception as e:
error "connectorCallRPCTask failed", error=e.msg
arg.finish(%* {
"requestId": arg.requestId,
"error": e.msg
})

49 changes: 47 additions & 2 deletions src/app_service/service/connector/service.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,31 @@ import app/global/global_singleton

import app/core/eventemitter
import app/core/signals/types
import app/core/tasks/[qt, threadpool]

import strutils

logScope:
topics = "connector-service"

include ./async_tasks

const SIGNAL_CONNECTOR_SEND_REQUEST_ACCOUNTS* = "ConnectorSendRequestAccounts"
const SIGNAL_CONNECTOR_EVENT_CONNECTOR_SEND_TRANSACTION* = "ConnectorSendTransaction"
const SIGNAL_CONNECTOR_GRANT_DAPP_PERMISSION* = "ConnectorGrantDAppPermission"
const SIGNAL_CONNECTOR_REVOKE_DAPP_PERMISSION* = "ConnectorRevokeDAppPermission"
const SIGNAL_CONNECTOR_EVENT_CONNECTOR_SIGN* = "ConnectorSign"
const SIGNAL_CONNECTOR_CALL_RPC_RESULT* = "ConnectorCallRPCResult"
const SIGNAL_CONNECTOR_DAPP_CHAIN_ID_SWITCHED* = "ConnectorDAppChainIdSwitched"

# Enum with events
type Event* = enum
DappConnect

type ConnectorCallRPCResultArgs* = ref object of Args
requestId*: int
payload*: string

# Event handler function
type EventHandlerFn* = proc(event: Event, payload: string)

Expand All @@ -31,15 +40,18 @@ QtObject:
type Service* = ref object of QObject
events: EventEmitter
eventHandler: EventHandlerFn
threadpool: ThreadPool

proc delete*(self: Service)
proc newService*(
events: EventEmitter
events: EventEmitter,
threadpool: ThreadPool
): Service =
new(result, delete)
result.QObject.setup

result.events = events
result.threadpool = threadpool

proc init*(self: Service) =
self.events.on(SignalType.ConnectorSendRequestAccounts.event, proc(e: Args) =
Expand Down Expand Up @@ -94,6 +106,13 @@ QtObject:

self.events.emit(SIGNAL_CONNECTOR_EVENT_CONNECTOR_SIGN, data)
)
self.events.on(SignalType.ConnectorDAppChainIdSwitched.event, proc(e: Args) =
if self.eventHandler == nil:
return

var data = ConnectorDAppChainIdSwitchedSignal(e)
self.events.emit(SIGNAL_CONNECTOR_DAPP_CHAIN_ID_SWITCHED, data)
)

proc registerEventsHandler*(self: Service, handler: EventHandlerFn) =
self.eventHandler = handler
Expand All @@ -105,7 +124,7 @@ QtObject:
args.requestId = requestId
args.account = account
args.chainId = chainId

return status_go.requestAccountsAcceptedFinishedRpc(args)

except Exception as e:
Expand Down Expand Up @@ -178,6 +197,32 @@ QtObject:
proc rejectSigning*(self: Service, requestId: string): bool =
rejectRequest(self, requestId, status_go.sendSignRejectedFinishedRpc, "sendSignRejectedFinishedRpc failed: ")

proc onConnectorCallRPCResolved*(self: Service, response: string) {.slot.} =
try:
let responseObj = response.parseJson
let requestId = responseObj{"requestId"}.getInt(0)

var data = ConnectorCallRPCResultArgs()
data.requestId = requestId
data.payload = response

self.events.emit(SIGNAL_CONNECTOR_CALL_RPC_RESULT, data)
except Exception as e:
error "onConnectorCallRPCResolved failed", error=e.msg

proc connectorCallRPC*(self: Service, requestId: int, message: string) =
try:
let arg = ConnectorCallRPCTaskArg(
tptr: connectorCallRPCTask,
vptr: cast[uint](self.vptr),
slot: "onConnectorCallRPCResolved",
requestId: requestId,
message: message
)
self.threadpool.start(arg)
except:
error "connectorCallRPC: starting async background task failed", requestId=requestId

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

5 changes: 3 additions & 2 deletions src/app_service/service/wallet_connect/async_tasks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ proc asyncEstimateGasTask(argsEncoded: string) {.gcsafe, nimcall.} =
let tx = parseJson(arg.txJson)
let transaction = %*{
"from": tx["from"].getStr,
"to": tx["to"].getStr,
"data": tx["data"].getStr
"to": tx["to"].getStr
}
if tx.hasKey("data"):
transaction["data"] = tx["data"]
if tx.hasKey("value"):
transaction["value"] = tx["value"]

Expand Down
12 changes: 11 additions & 1 deletion src/backend/connector.nim
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import options
import json, json_serialization
import core, response_type
import chronicles

from gen import rpc

logScope:
topics = "connector-backend"

const
EventConnectorSendRequestAccounts* = "connector.sendRequestAccounts"
EventConnectorSendTransaction* = "connector.sendTransaction"
Expand Down Expand Up @@ -51,6 +55,9 @@ rpc(signAccepted, "connector"):
rpc(signRejected, "connector"):
args: RejectedArgs

rpc(callRPC, "connector"):
inputJSON: string

proc isSuccessResponse(rpcResponse: RpcResponse[JsonNode]): bool =
return rpcResponse.error.isNil

Expand All @@ -73,4 +80,7 @@ proc sendSignAcceptedFinishedRpc*(args: SignAcceptedArgs): bool =
return isSuccessResponse(signAccepted(args))

proc sendSignRejectedFinishedRpc*(args: RejectedArgs): bool =
return isSuccessResponse(signRejected(args))
return isSuccessResponse(signRejected(args))

proc connectorCallRPC*(inputJSON: string): RpcResponse[JsonNode] {.raises: [Exception].} =
return callRPC(inputJSON)