feat(@desktop/keycard): wallet account service extended

new procs added to the wallet account service:
- `addMigratedKeyPair`
- `getAllMigratedKeyPairs`
- `getMigratedKeyPairByKeyUID`
- `setKeycardName`
- `keycardLocked`
- `keycardUnlocked`
- `deleteKeycard`
This commit is contained in:
Sale Djenic 2022-09-13 12:00:12 +02:00 committed by saledjenic
parent fb5065da16
commit 6e9cb37766
4 changed files with 123 additions and 5 deletions

View File

@ -44,6 +44,7 @@ type
name*: string
address*: string
mixedcaseAddress*: string
keyUid*: string
path*: string
color*: string
publicKey*: string
@ -87,6 +88,7 @@ proc toWalletAccountDto*(jsonObj: JsonNode): WalletAccountDto =
discard jsonObj.getProp("name", result.name)
discard jsonObj.getProp("address", result.address)
discard jsonObj.getProp("mixedcase-address", result.mixedcaseAddress)
discard jsonObj.getProp("key-uid", result.keyUid)
discard jsonObj.getProp("path", result.path)
discard jsonObj.getProp("color", result.color)
discard jsonObj.getProp("wallet", result.isWallet)

View File

@ -0,0 +1,22 @@
import json
include ../../common/json_utils
type KeyPairDto* = object
keycardUid*: string
keypairName*: string
keycardLocked*: bool
accountsAddresses*: seq[string]
keyUid*: string
proc toKeyPairDto*(jsonObj: JsonNode): KeyPairDto =
result = KeyPairDto()
discard jsonObj.getProp("keycard-uid", result.keycardUid)
discard jsonObj.getProp("keypair-name", result.keypairName)
discard jsonObj.getProp("keycard-locked", result.keycardLocked)
discard jsonObj.getProp("key-uid", result.keyUid)
var jArr: JsonNode
if(jsonObj.getProp("accounts-addresses", jArr) and jArr.kind == JArray):
for addrObj in jArr:
result.accountsAddresses.add(addrObj.getStr)

View File

@ -8,8 +8,7 @@ import ../network/service as network_service
import ../../common/account_constants
import ../../../app/global/global_singleton
import dto
import derived_address
import dto, derived_address, key_pair_dto
import ../../../app/core/eventemitter
import ../../../app/core/signals/types
@ -20,8 +19,7 @@ import ../../../backend/eth as status_go_eth
import ../../../backend/transactions as status_go_transactions
import ../../../backend/cache
export dto
export derived_address
export dto, derived_address, key_pair_dto
logScope:
topics = "wallet-account-service"
@ -472,4 +470,75 @@ QtObject:
let balanceForToken = tokenBalances{address}{token.addressAsString()}.getStr
let chainBalanceForToken = parsefloat(hex2Balance(balanceForToken, token.decimals))
totalBalance = totalBalance + chainBalanceForToken * prices[token.symbol]
return totalBalance
return totalBalance
proc responseHasNoErrors(self: Service, procName: string, response: RpcResponse[JsonNode]): bool =
var errMsg = ""
if not response.error.isNil:
errMsg = "(" & $response.error.code & ") " & response.error.message
elif response.result.kind == JObject and response.result.contains("error"):
errMsg = response.result["error"].getStr
if(errMsg.len == 0):
return true
error "error: ", procName=procName, errDesription = errMsg
return false
proc addMigratedKeyPair*(self: Service, keyPair: KeyPairDto): bool =
try:
let response = backend.addMigratedKeyPair(
keyPair.keycardUid,
keyPair.keyPairName,
keyPair.keyUid,
keyPair.accountsAddresses)
return self.responseHasNoErrors("addMigratedKeyPair", response)
except Exception as e:
error "error: ", procName="addMigratedKeyPair", errName = e.name, errDesription = e.msg
return false
proc getAllMigratedKeyPairs*(self: Service): seq[KeyPairDto] =
try:
let response = backend.getAllMigratedKeyPairs()
if self.responseHasNoErrors("getAllMigratedKeyPairs", response):
return map(response.result.getElems(), proc(x: JsonNode): KeyPairDto = toKeyPairDto(x))
except Exception as e:
error "error: ", procName="getAllMigratedKeyPairs", errName = e.name, errDesription = e.msg
proc getMigratedKeyPairByKeyUid*(self: Service, keyUid: string): seq[KeyPairDto] =
try:
let response = backend.getMigratedKeyPairByKeyUID(keyUid)
if self.responseHasNoErrors("getMigratedKeyPairByKeyUid", response):
return map(response.result.getElems(), proc(x: JsonNode): KeyPairDto = toKeyPairDto(x))
except Exception as e:
error "error: ", procName="getMigratedKeyPairByKeyUid", errName = e.name, errDesription = e.msg
proc setKeycardName*(self: Service, keycardUid: string, name: string): bool =
try:
let response = backend.setKeycardName(keycardUid, name)
return self.responseHasNoErrors("setKeycardName", response)
except Exception as e:
error "error: ", procName="setKeycardName", errName = e.name, errDesription = e.msg
return false
proc setKeycardLocked*(self: Service, keycardUid: string): bool =
try:
let response = backend.keycardLocked(keycardUid)
return self.responseHasNoErrors("setKeycardLocked", response)
except Exception as e:
error "error: ", procName="setKeycardLocked", errName = e.name, errDesription = e.msg
return false
proc setKeycardUnlocked*(self: Service, keycardUid: string): bool =
try:
let response = backend.keycardUnlocked(keycardUid)
return self.responseHasNoErrors("setKeycardUnlocked", response)
except Exception as e:
error "error: ", procName="setKeycardUnlocked", errName = e.name, errDesription = e.msg
return false
proc deleteKeycard*(self: Service, keycardUid: string): bool =
try:
let response = backend.deleteKeycard(keycardUid)
return self.responseHasNoErrors("deleteKeycard", response)
except Exception as e:
error "error: ", procName="deleteKeycard", errName = e.name, errDesription = e.msg
return false

View File

@ -211,3 +211,28 @@ rpc(fetchMarketValues, "wallet"):
rpc(fetchTokenDetails, "wallet"):
symbols: seq[string]
rpc(addMigratedKeyPair, "accounts"):
keycardUid: string
keyPairName: string
keyUid: string
accountAddresses: seq[string]
rpc(getAllMigratedKeyPairs, "accounts"):
discard
rpc(getMigratedKeyPairByKeyUID, "accounts"):
keyUid: string
rpc(setKeycardName, "accounts"):
keycardUid: string
keyPairName: string
rpc(keycardLocked, "accounts"):
keycardUid: string
rpc(keycardUnlocked, "accounts"):
keycardUid: string
rpc(deleteKeycard, "accounts"):
keycardUid: string