chore(@desktop): add utility to get color id for pubkey

This commit is contained in:
Patryk Osmaczko 2022-04-07 20:55:04 +02:00 committed by Iuri Matias
parent 3bf4d65a74
commit f2898b6bf7
5 changed files with 27 additions and 0 deletions

View File

@ -142,5 +142,8 @@ QtObject:
proc getColorHashAsJson*(self: Utils, publicKey: string): string {.slot.} =
procs_from_visual_identity_service.getColorHashAsJson(publicKey)
proc getColorId*(self: Utils, publicKey: string): int {.slot.} =
int(procs_from_visual_identity_service.colorIdOf(publicKey))
proc getCompressedPk*(self: Utils, publicKey: string): string {.slot.} =
procs_from_accounts.compressPk(publicKey)

View File

@ -1,6 +1,7 @@
{.used.}
import json
import ../../visual_identity/dto
include ../../../common/json_utils
@ -20,6 +21,8 @@ type AccountDto* = object
keycardPairing*: string
keyUid*: string
images*: seq[Image]
colorHash*: ColorHashDto
colorId*: int
proc isValid*(self: AccountDto): bool =
result = self.name.len > 0 and self.keyUid.len > 0
@ -40,6 +43,8 @@ proc toAccountDto*(jsonObj: JsonNode): AccountDto =
discard jsonObj.getProp("timestamp", result.timestamp)
discard jsonObj.getProp("keycard-pairing", result.keycardPairing)
discard jsonObj.getProp("key-uid", result.keyUid)
discard jsonObj.getProp("colorId", result.colorId)
result.colorHash = toColorHashDto(jsonObj["colorHash"])
var imagesObj: JsonNode
if(jsonObj.getProp("images", imagesObj) and imagesObj.kind == JArray):

View File

@ -15,3 +15,6 @@ proc toColorHashDto*(jsonObj: JsonNode): ColorHashDto =
colorIdx: node.getElems()[1].getInt())
)
return
proc toColorId*(jsonObj: JsonNode): int =
return jsonObj.getInt()

View File

@ -31,6 +31,19 @@ proc colorHashOf*(pubkey: string): ColorHashDto =
error "error: ", procName = "colorHashOf", errName = e.name,
errDesription = e.msg
proc colorIdOf*(pubkey: string): int =
try:
let response = status_visual_identity.colorIdOf(pubkey)
if(not response.error.isNil):
error "error colorIdOf: ", errDescription = response.error.message
result = toColorId(response.result)
except Exception as e:
error "error: ", procName = "colorIdOf", errName = e.name,
errDesription = e.msg
proc getEmojiHashAsJson*(publicKey: string): string =
return $$emojiHashOf(publicKey)

View File

@ -10,3 +10,6 @@ proc emojiHashOf*(pubkey: string): RpcResponse[JsonNode] {.raises: [Exception].}
proc colorHashOf*(pubkey: string): RpcResponse[JsonNode] {.raises: [Exception].} =
result = Json.decode(status_go.colorHash(pubkey), RpcResponse[JsonNode])
proc colorIdOf*(pubkey: string): RpcResponse[JsonNode] {.raises: [Exception].} =
result = Json.decode(status_go.colorID(pubkey), RpcResponse[JsonNode])