feat(@desktop/keycard): recover an account fetching previously backed up data from waku

Closes: #8920
This commit is contained in:
Sale Djenic 2023-02-27 14:36:54 +01:00 committed by Anthony Laibe
parent 8a1e1947ae
commit bf9b709cc8
17 changed files with 70 additions and 8 deletions

View File

@ -50,6 +50,7 @@ type SignalType* {.pure.} = enum
WakuFetchingBackupProgress = "waku.fetching.backup.progress"
WakuBackedUpProfile = "waku.backedup.profile"
WakuBackedUpSettings = "waku.backedup.settings"
WakuBackedUpKeycards = "waku.backedup.keycards"
Unknown
proc event*(self:SignalType):string =

View File

@ -0,0 +1,14 @@
import json
import base
import ../../../../app_service/service/wallet_account/[key_pair_dto]
type WakuBackedUpKeycardsSignal* = ref object of Signal
keycards*: seq[KeyPairDto]
proc fromEvent*(T: type WakuBackedUpKeycardsSignal, event: JsonNode): WakuBackedUpKeycardsSignal =
result = WakuBackedUpKeycardsSignal()
if event["event"]{"backedUpKeycards"} != nil:
for jsonKc in event["event"]["backedUpKeycards"]:
result.keycards.add(jsonKc.toKeyPairDto())

View File

@ -105,6 +105,7 @@ QtObject:
of SignalType.WakuFetchingBackupProgress: WakuFetchingBackupProgressSignal.fromEvent(jsonSignal)
of SignalType.WakuBackedUpProfile: WakuBackedUpProfileSignal.fromEvent(jsonSignal)
of SignalType.WakuBackedUpSettings: WakuBackedUpSettingsSignal.fromEvent(jsonSignal)
of SignalType.WakuBackedUpKeycards: WakuBackedUpKeycardsSignal.fromEvent(jsonSignal)
else: Signal()
result.signalType = signalType

View File

@ -2,8 +2,8 @@
import ./remote_signals/[base, chronicles_logs, community, discovery_summary, envelope, expired, mailserver, messages,
peerstats, signal_type, stats, wallet, whisper_filter, keycard, update_available, status_updates, waku_backed_up_profile,
waku_backed_up_settings, waku_fetching_backup_progress]
waku_backed_up_settings, waku_backed_up_keycards, waku_fetching_backup_progress]
export base, chronicles_logs, community, discovery_summary, envelope, expired, mailserver, messages, peerstats,
signal_type, stats, wallet, whisper_filter, keycard, update_available, status_updates, waku_backed_up_profile,
waku_backed_up_settings, waku_fetching_backup_progress
waku_backed_up_settings, waku_backed_up_keycards, waku_fetching_backup_progress

View File

@ -127,3 +127,6 @@ proc authenticateLoggedInUser*(self: Controller) =
if singletonInstance.userProfile.getIsKeycardUser():
data.keyUid = singletonInstance.userProfile.getKeyUid()
self.events.emit(SIGNAL_SHARED_KEYCARD_MODULE_AUTHENTICATE_USER, data)
proc backupData*(self: Controller): int64 =
return self.generalService.backupData()

View File

@ -73,3 +73,6 @@ method tryRemoveFromKeyChain*(self: AccessInterface) {.base.} =
method onUserAuthenticated*(self: AccessInterface, pin: string, password: string, keyUid: string) {.base.} =
raise newException(ValueError, "No implementation available")
method backupData*(self: AccessInterface): int64 {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -118,3 +118,6 @@ method onUserAuthenticated*(self: Module, pin: string, password: string, keyUid:
self.controller.storeToKeychain(pin)
else:
self.controller.storeToKeychain(password)
method backupData*(self: Module): int64 =
return self.controller.backupData()

View File

@ -78,3 +78,5 @@ QtObject:
proc tryRemoveFromKeyChain*(self: View) {.slot.} =
self.delegate.tryRemoveFromKeyChain()
proc backupData*(self: View): int {.slot.} =
return self.delegate.backupData().int

View File

@ -32,6 +32,8 @@ const FetchingFromWakuCommunities = "communities"
const FetchingFromWakuCommunitiesIcon = "communities"
const FetchingFromWakuSettings = "settings"
const FetchingFromWakuSettingsIcon = "settings"
const FetchingFromWakuKeycards = "keycards"
const FetchingFromWakuKeycardIcon = "keycard"
type
Module*[T: io_interface.DelegateInterface] = ref object of io_interface.AccessInterface
@ -338,7 +340,8 @@ proc prepareAndInitFetchingData[T](self: Module[T]) =
(FetchingFromWakuProfile, FetchingFromWakuProfileIcon),
(FetchingFromWakuContacts, FetchingFromWakuContactsIcon),
(FetchingFromWakuCommunities, FetchingFromWakuCommunitiesIcon),
(FetchingFromWakuSettings, FetchingFromWakuSettingsIcon)
(FetchingFromWakuSettings, FetchingFromWakuSettingsIcon),
(FetchingFromWakuKeycards, FetchingFromWakuKeycardIcon)
]
self.view.createAndInitFetchingDataModel(listOfEntitiesWeExpectToBeSynced)

View File

@ -94,3 +94,10 @@ QtObject:
error "could not set display name"
except Exception as e:
error "error: ", procName="fetchWakuMessages", errName = e.name, errDesription = e.msg
proc backupData*(self: Service): int64 =
try:
let response = status_general.backupData()
return response.result.getInt
except Exception as e:
error "error: ", procName="backupData", errName = e.name, errDesription = e.msg

View File

@ -78,3 +78,7 @@ proc initKeystore*(keystoreDir: string): RpcResponse[JsonNode] {.raises: [Except
except RpcException as e:
error "error", methodName = "initKeystore", exception=e.msg
raise newException(RpcException, e.msg)
proc backupData*(): RpcResponse[JsonNode] {.raises: [Exception].} =
let payload = %* []
result = callPrivateRPC("backupData".prefix, payload)

View File

@ -92,6 +92,8 @@ Item {
return qsTr("Community membership")
case Constants.onboarding.profileFetching.entity.settings:
return qsTr("Settings")
case Constants.onboarding.profileFetching.entity.keycards:
return qsTr("Keycards")
}
}
}

View File

@ -223,6 +223,7 @@ StatusSectionLayout {
implicitHeight: parent.height
devicesStore: root.store.devicesStore
privacyStore: root.store.privacyStore
sectionTitle: root.store.getNameForSubsection(Constants.settingsSubsection.devicesSettings)
contentWidth: d.contentWidth
}

View File

@ -36,4 +36,8 @@ QtObject {
function tryRemoveFromKeyChain() {
root.privacyModule.tryRemoveFromKeyChain()
}
function backupData() {
return root.privacyModule.backupData()
}
}

View File

@ -18,6 +18,7 @@ SettingsContentBase {
id: root
property DevicesStore devicesStore
property PrivacyStore privacyStore
property bool isSyncing: false
@ -229,6 +230,18 @@ SettingsContentBase {
}, 10000);
}
}
StatusButton {
id: backupBtn
anchors.top: syncAllBtn.bottom
anchors.topMargin: Style.current.padding
anchors.horizontalCenter: listView.horizontalCenter
text: qsTr("Backup Data")
onClicked : {
let lastUpdate = root.privacyStore.backupData() * 1000
console.log("Backup done at: ", LocaleUtils.formatDateTime(lastUpdate))
}
}
}
Timer {

View File

@ -364,6 +364,7 @@ QtObject {
readonly property string contacts: "contacts"
readonly property string communities: "communities"
readonly property string settings: "settings"
readonly property string keycards: "keycards"
}
}
}

2
vendor/status-go vendored

@ -1 +1 @@
Subproject commit 60e1978bb5917078830aab13e1f2e1b3da17e865
Subproject commit 93de01e32e8e8bfa57e0c1f76b525b815cf0c08d