feat(@wallet): verify json rpc URL
This commit is contained in:
parent
313e5a5b69
commit
3ea5464c33
|
@ -34,6 +34,10 @@ proc init*(self: Controller) =
|
|||
self.events.on(SIGNAL_WALLET_ACCOUNT_NETWORK_ENABLED_UPDATED) do(e: Args):
|
||||
self.delegate.refreshNetworks()
|
||||
|
||||
self.events.on(SIGNAL_WALLET_ACCOUNT_CHAIN_ID_FOR_URL_FETCHED) do(e: Args):
|
||||
let args = ChainIdForUrlArgs(e)
|
||||
self.delegate.chainIdFetchedForUrl(args.url, args.chainId, args.success)
|
||||
|
||||
proc getNetworks*(self: Controller): seq[CombinedNetworkDto] =
|
||||
return self.networkService.getCombinedNetworks()
|
||||
|
||||
|
@ -43,5 +47,8 @@ proc areTestNetworksEnabled*(self: Controller): bool =
|
|||
proc toggleTestNetworksEnabled*(self: Controller) =
|
||||
self.walletAccountService.toggleTestNetworksEnabled()
|
||||
|
||||
proc fetchChainIdForUrl*(self: Controller, url: string) =
|
||||
self.walletAccountService.fetchChainIdForUrl(url)
|
||||
|
||||
proc updateNetworkEndPointValues*(self: Controller, chainId: int, newMainRpcInput, newFailoverRpcUrl: string) =
|
||||
self.networkService.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl)
|
||||
|
|
|
@ -30,3 +30,9 @@ method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
|
|||
|
||||
method updateNetworkEndPointValues*(self: AccessInterface, chainId: int, newMainRpcInput, newFailoverRpcUrl: string) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method fetchChainIdForUrl*(self: AccessInterface, url: string) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method chainIdFetchedForUrl*(self: AccessInterface, url: string, chainId: int, success: bool) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
|
|
@ -93,3 +93,9 @@ method toggleTestNetworksEnabled*(self: Module) =
|
|||
|
||||
method updateNetworkEndPointValues*(self: Module, chainId: int, newMainRpcInput, newFailoverRpcUrl: string) =
|
||||
self.controller.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl)
|
||||
|
||||
method fetchChainIdForUrl*(self: Module, url: string) =
|
||||
self.controller.fetchChainIdForUrl(url)
|
||||
|
||||
method chainIdFetchedForUrl*(self: Module, url: string, chainId: int, success: bool) =
|
||||
self.view.chainIdFetchedForUrl(url, chainId, success)
|
|
@ -62,3 +62,8 @@ QtObject:
|
|||
|
||||
proc updateNetworkEndPointValues*(self: View, chainId: int, newMainRpcInput, newFailoverRpcUrl: string) =
|
||||
self.delegate.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl)
|
||||
|
||||
proc fetchChainIdForUrl*(self: View, url: string) {.slot.} =
|
||||
self.delegate.fetchChainIdForUrl(url)
|
||||
|
||||
proc chainIdFetchedForUrl*(self: View, url: string, chainId: int, success: bool) {.signal.}
|
|
@ -154,4 +154,30 @@ const deleteKeycardAccountsTask*: Task = proc(argEncoded: string) {.gcsafe, nimc
|
|||
responseJson["success"] = %* success
|
||||
except Exception as e:
|
||||
error "error remove accounts from keycard: ", message = e.msg
|
||||
|
||||
arg.finish(responseJson)
|
||||
|
||||
#################################################
|
||||
# Async fetch chain id for url
|
||||
#################################################
|
||||
|
||||
type
|
||||
FetchChainIdForUrlTaskArg* = ref object of QObjectTaskArg
|
||||
url: string
|
||||
|
||||
const fetchChainIdForUrlTask*: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
|
||||
let arg = decode[FetchChainIdForUrlTaskArg](argEncoded)
|
||||
try:
|
||||
let response = backend.fetchChainIDForURL(arg.url)
|
||||
arg.finish(%*{
|
||||
"success": true,
|
||||
"chainId": response.result.getInt,
|
||||
"url": arg.url
|
||||
})
|
||||
except Exception as e:
|
||||
error "error when fetching chaind id from url: ", message = e.msg
|
||||
arg.finish(%*{
|
||||
"success": false,
|
||||
"chainId": -1,
|
||||
"url": arg.url
|
||||
})
|
||||
|
|
|
@ -35,7 +35,8 @@ const SIGNAL_WALLET_ACCOUNT_DERIVED_ADDRESSES_FETCHED* = "walletAccount/derivedA
|
|||
const SIGNAL_WALLET_ACCOUNT_DERIVED_ADDRESSES_FROM_MNEMONIC_FETCHED* = "walletAccount/derivedAddressesFromMnemonicFetched"
|
||||
const SIGNAL_WALLET_ACCOUNT_ADDRESS_DETAILS_FETCHED* = "walletAccount/addressDetailsFetched"
|
||||
const SIGNAL_WALLET_ACCOUNT_POSITION_UPDATED* = "walletAccount/positionUpdated"
|
||||
const SIGNAL_WALLET_ACCOUNT_OPERABILITY_UPDATED* = "walletAccount/operabilityUpdated" # TODO: will be used later, when we deal with account operability
|
||||
const SIGNAL_WALLET_ACCOUNT_OPERABILITY_UPDATED* = "walletAccount/operabilityUpdated"
|
||||
const SIGNAL_WALLET_ACCOUNT_CHAIN_ID_FOR_URL_FETCHED* = "walletAccount/chainIdForUrlFetched"
|
||||
|
||||
const SIGNAL_KEYPAIR_SYNCED* = "keypairSynced"
|
||||
const SIGNAL_KEYPAIR_NAME_CHANGED* = "keypairNameChanged"
|
||||
|
@ -96,6 +97,16 @@ type TokensPerAccountArgs* = ref object of Args
|
|||
hasBalanceCache*: bool
|
||||
hasMarketValuesCache*: bool
|
||||
|
||||
type KeycardActivityArgs* = ref object of Args
|
||||
success*: bool
|
||||
oldKeycardUid*: string
|
||||
keycard*: KeycardDto
|
||||
|
||||
type ChainIdForUrlArgs* = ref object of Args
|
||||
chainId*: int
|
||||
success*: bool
|
||||
url*: string
|
||||
|
||||
proc responseHasNoErrors(procName: string, response: RpcResponse[JsonNode]): bool =
|
||||
var errMsg = ""
|
||||
if not response.error.isNil:
|
||||
|
@ -999,3 +1010,20 @@ QtObject:
|
|||
|
||||
proc toggleIncludeWatchOnlyAccount*(self: Service) =
|
||||
self.settingsService.toggleIncludeWatchOnlyAccount()
|
||||
|
||||
proc onFetchChainIdForUrl*(self: Service, jsonString: string) {.slot.} =
|
||||
let response = parseJson(jsonString)
|
||||
self.events.emit(SIGNAL_WALLET_ACCOUNT_CHAIN_ID_FOR_URL_FETCHED, ChainIdForUrlArgs(
|
||||
chainId: response{"chainId"}.getInt,
|
||||
success: response{"success"}.getBool,
|
||||
url: response{"url"}.getStr,
|
||||
))
|
||||
|
||||
proc fetchChainIdForUrl*(self: Service, url: string) =
|
||||
let arg = FetchChainIdForUrlTaskArg(
|
||||
tptr: cast[ByteAddress](fetchChainIdForUrlTask),
|
||||
vptr: cast[ByteAddress](self.vptr),
|
||||
slot: "onFetchChainIdForUrl",
|
||||
url: url
|
||||
)
|
||||
self.threadpool.start(arg)
|
|
@ -73,6 +73,9 @@ rpc(addEthereumChain, "wallet"):
|
|||
rpc(deleteEthereumChain, "wallet"):
|
||||
chainId: int
|
||||
|
||||
rpc(fetchChainIDForURL, "wallet"):
|
||||
url: string
|
||||
|
||||
rpc(upsertSavedAddress, "wakuext"):
|
||||
savedAddress: SavedAddress
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ QtObject {
|
|||
}
|
||||
|
||||
function evaluateRpcEndPoint(url) {
|
||||
// TODO: connect with nim api once its ready
|
||||
return networksModule.fetchChainIdForUrl(url)
|
||||
}
|
||||
|
||||
function updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl) {
|
||||
|
|
|
@ -13,7 +13,7 @@ ColumnLayout {
|
|||
|
||||
property var network
|
||||
property var networksModule
|
||||
signal evaluateEndPoint(string url)
|
||||
signal evaluateRpcEndPoint(string url)
|
||||
signal updateNetworkValues(int chainId, string newMainRpcInput, string newFailoverRpcUrl)
|
||||
|
||||
enum EvaluationState {
|
||||
|
@ -29,7 +29,7 @@ ColumnLayout {
|
|||
property int evaluationStatus: EditNetworkForm.UnTouched
|
||||
property int evaluationStatusFallBackRpc: EditNetworkForm.UnTouched
|
||||
property var evaluateRpcEndPoint: Backpressure.debounce(root, 400, function (value) {
|
||||
root.evaluateEndPoint(value)
|
||||
root.evaluateRpcEndPoint(value)
|
||||
})
|
||||
|
||||
function revertValues() {
|
||||
|
@ -61,7 +61,11 @@ ColumnLayout {
|
|||
|
||||
Connections {
|
||||
target: networksModule
|
||||
function onUrlVerified(url, status) {
|
||||
function onChainIdFetchedForUrl(url, chainId, success) {
|
||||
let status = EditNetworkForm.PingUnsuccessful
|
||||
if(success) {
|
||||
status = EditNetworkForm.Verified
|
||||
}
|
||||
if(url === mainRpcInput.text) {
|
||||
d.evaluationStatus = status
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ ColumnLayout {
|
|||
id: editLiveNetwork
|
||||
network: !!root.combinedNetwork ? root.combinedNetwork.prod: null
|
||||
networksModule: root.networksModule
|
||||
onEvaluateEndPoint: root.evaluateRpcEndPoint(url)
|
||||
onEvaluateRpcEndPoint: root.evaluateRpcEndPoint(url)
|
||||
onUpdateNetworkValues: root.updateNetworkValues(chainId, newMainRpcInput, newFailoverRpcUrl)
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ ColumnLayout {
|
|||
id: editTestNetwork
|
||||
network: !!root.combinedNetwork ? root.combinedNetwork.test: null
|
||||
networksModule: root.networksModule
|
||||
onEvaluateEndPoint: root.evaluateRpcEndPoint(url)
|
||||
onEvaluateRpcEndPoint: root.evaluateRpcEndPoint(url)
|
||||
onUpdateNetworkValues: root.updateNetworkValues(chainId, newMainRpcInput, newFailoverRpcUrl)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 9674bc463f08907887317bd030444666a1022126
|
||||
Subproject commit 0f8347dc59c7058c275c5eb72431ad7e445f0f9d
|
Loading…
Reference in New Issue