almost working

This commit is contained in:
howard-stearns 2018-02-23 16:12:01 -08:00
parent 47b25740de
commit 53614a1d9f
6 changed files with 27 additions and 5 deletions

View file

@ -47,7 +47,7 @@ Rectangle {
}
} else if (walletStatus === 1) {
if (root.activeView !== "walletSetup") {
walletSetup();
walletResetSetup();
}
} else if (walletStatus === 2) {
if (root.activeView != "preexisting") {
@ -177,12 +177,13 @@ Rectangle {
proceedFunction: function (isReset) {
console.log(isReset ? "Reset wallet." : "Trying again with new wallet.");
if (isReset) {
walletSetup();
walletResetSetup();
} else {
root.activeView = "initialize";
Commerce.getWalletStatus();
}
}
copyFunction: Commerce.copyKeyFileFrom;
z: 997;
visible: (root.activeView === "preexisting") || (root.activeView === "conflicting");
activeView: root.activeView;
@ -789,7 +790,7 @@ Rectangle {
});
}
function walletSetup() {
function walletResetSetup() {
root.activeView = "walletSetup";
Commerce.resetLocalWalletOnly();
var timestamp = new Date();

View file

@ -24,6 +24,7 @@ Item {
id: root;
property string activeView: "conflict";
property var proceedFunction: nil;
property var copyFunction: nil;
Image {
anchors.fill: parent;
@ -272,8 +273,11 @@ Item {
console.log('WalletChoice.qml ignoring', e);
}
if (filename) {
console.log("FIXME copy file to the right place");
proceed(false);
if (copyFunction && copyFunction(filename)) {
proceed(false);
} else {
console.log("WalletChoice.qml copyFunction", copyFunction, "failed.");
}
} // Else we're still at WalletChoice
}
function walletChooser() {

View file

@ -52,6 +52,11 @@ void QmlCommerce::getKeyFilePathIfExists() {
emit keyFilePathIfExistsResult(wallet->getKeyFilePath());
}
bool QmlCommerce::copyKeyFileFrom(const QString& pathname) {
auto wallet = DependencyManager::get<Wallet>();
return wallet->copyKeyFileFrom(pathname);
}
void QmlCommerce::getWalletAuthenticatedStatus() {
auto wallet = DependencyManager::get<Wallet>();
emit walletAuthenticatedStatusResult(wallet->walletIsAuthenticatedWithPassphrase());

View file

@ -55,6 +55,7 @@ protected:
Q_INVOKABLE void getKeyFilePathIfExists();
Q_INVOKABLE void getSecurityImage();
Q_INVOKABLE void getWalletAuthenticatedStatus();
Q_INVOKABLE bool copyKeyFileFrom(const QString& pathname);
Q_INVOKABLE void chooseSecurityImage(const QString& imageFile);
Q_INVOKABLE void setPassphrase(const QString& passphrase);

View file

@ -59,6 +59,16 @@ QString keyFilePath() {
auto accountManager = DependencyManager::get<AccountManager>();
return PathUtils::getAppDataFilePath(QString("%1.%2").arg(accountManager->getAccountInfo().getUsername(), KEY_FILE));
}
bool Wallet::copyKeyFileFrom(const QString& pathname) {
QString existing = getKeyFilePath();
if (!existing.isEmpty()) {
if (!QFile::rename(existing, existing + ".backup" + QDateTime::currentDateTime().toString(Qt::ISODate))) {
qCCritical(commerce) << "Unable to backup" << existing;
return false;
}
}
return QFile::copy(pathname, keyFilePath());
}
// use the cached _passphrase if it exists, otherwise we need to prompt
int passwordCallback(char* password, int maxPasswordSize, int rwFlag, void* u) {

View file

@ -35,6 +35,7 @@ public:
void chooseSecurityImage(const QString& imageFile);
bool getSecurityImage();
QString getKeyFilePath();
bool copyKeyFileFrom(const QString& pathname);
void setSalt(const QByteArray& salt) { _salt = salt; }
QByteArray getSalt() { return _salt; }