mirror of
https://github.com/overte-org/overte.git
synced 2025-04-22 09:13:28 +02:00
Merge pull request #11273 from howard-stearns/reset-wallet
reset wallet
This commit is contained in:
commit
84e13c84ae
11 changed files with 95 additions and 10 deletions
interface
resources/qml/hifi/commerce/wallet
src/commerce
libraries/ui/src/ui
scripts/system/commerce
|
@ -31,6 +31,7 @@ Item {
|
|||
|
||||
// "Unavailable"
|
||||
RalewayRegular {
|
||||
id: helpText;
|
||||
text: "Help me!";
|
||||
// Anchors
|
||||
anchors.fill: parent;
|
||||
|
@ -43,6 +44,19 @@ Item {
|
|||
horizontalAlignment: Text.AlignHCenter;
|
||||
verticalAlignment: Text.AlignVCenter;
|
||||
}
|
||||
HifiControlsUit.Button {
|
||||
color: hifi.buttons.black;
|
||||
colorScheme: hifi.colorSchemes.dark;
|
||||
anchors.bottom: helpText.bottom;
|
||||
anchors.horizontalCenter: parent.horizontalCenter;
|
||||
height: 50;
|
||||
width: 250;
|
||||
text: "Testing: Reset Wallet!";
|
||||
onClicked: {
|
||||
commerce.reset();
|
||||
sendSignalToWallet({method: 'walletReset'});
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// FUNCTION DEFINITIONS START
|
||||
|
|
|
@ -107,7 +107,7 @@ Rectangle {
|
|||
anchors.centerIn: walletSetupLightboxContainer;
|
||||
width: walletSetupLightboxContainer.width - 50;
|
||||
height: walletSetupLightboxContainer.height - 50;
|
||||
|
||||
|
||||
Connections {
|
||||
onSendSignalToWallet: {
|
||||
if (msg.method === 'walletSetup_raiseKeyboard') {
|
||||
|
@ -127,7 +127,7 @@ Rectangle {
|
|||
anchors.centerIn: walletSetupLightboxContainer;
|
||||
width: walletSetupLightboxContainer.width - 50;
|
||||
height: walletSetupLightboxContainer.height - 50;
|
||||
|
||||
|
||||
Connections {
|
||||
onSendSignalToWallet: {
|
||||
sendToScript(msg);
|
||||
|
@ -196,7 +196,7 @@ Rectangle {
|
|||
commerce.getLoginStatus();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NeedsLogIn {
|
||||
id: needsLogIn;
|
||||
visible: root.activeView === "needsLogIn";
|
||||
|
@ -225,7 +225,7 @@ Rectangle {
|
|||
anchors.bottom: tabButtonsContainer.top;
|
||||
anchors.left: parent.left;
|
||||
anchors.right: parent.right;
|
||||
|
||||
|
||||
Connections {
|
||||
onSendSignalToWallet: {
|
||||
if (msg.method === 'setUpClicked') {
|
||||
|
@ -296,6 +296,14 @@ Rectangle {
|
|||
anchors.leftMargin: 16;
|
||||
anchors.right: parent.right;
|
||||
anchors.rightMargin: 16;
|
||||
|
||||
Connections {
|
||||
onSendSignalToWallet: {
|
||||
if (msg.method === 'walletReset') {
|
||||
sendToScript(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -510,7 +518,7 @@ Rectangle {
|
|||
}
|
||||
//
|
||||
// TAB BUTTONS END
|
||||
//
|
||||
//
|
||||
|
||||
Item {
|
||||
id: keyboardContainer;
|
||||
|
|
|
@ -111,3 +111,10 @@ void Ledger::inventory(const QStringList& keys) {
|
|||
void Ledger::history(const QStringList& keys) {
|
||||
keysQuery("history", "historySuccess", "historyFailure");
|
||||
}
|
||||
|
||||
// The api/failResponse is called just for the side effect of logging.
|
||||
void Ledger::resetSuccess(QNetworkReply& reply) { apiResponse("reset", reply); }
|
||||
void Ledger::resetFailure(QNetworkReply& reply) { failResponse("reset", reply); }
|
||||
void Ledger::reset() {
|
||||
send("reset_user_hfc_account", "resetSuccess", "resetFailure", QNetworkAccessManager::PutOperation, QJsonObject());
|
||||
}
|
|
@ -29,6 +29,7 @@ public:
|
|||
void balance(const QStringList& keys);
|
||||
void inventory(const QStringList& keys);
|
||||
void history(const QStringList& keys);
|
||||
void reset();
|
||||
|
||||
signals:
|
||||
void buyResult(QJsonObject result);
|
||||
|
@ -48,6 +49,8 @@ public slots:
|
|||
void inventoryFailure(QNetworkReply& reply);
|
||||
void historySuccess(QNetworkReply& reply);
|
||||
void historyFailure(QNetworkReply& reply);
|
||||
void resetSuccess(QNetworkReply& reply);
|
||||
void resetFailure(QNetworkReply& reply);
|
||||
|
||||
private:
|
||||
QJsonObject apiResponse(const QString& label, QNetworkReply& reply);
|
||||
|
|
|
@ -85,3 +85,10 @@ void QmlCommerce::getKeyFilePathIfExists() {
|
|||
auto wallet = DependencyManager::get<Wallet>();
|
||||
wallet->sendKeyFilePathIfExists();
|
||||
}
|
||||
|
||||
void QmlCommerce::reset() {
|
||||
auto ledger = DependencyManager::get<Ledger>();
|
||||
auto wallet = DependencyManager::get<Wallet>();
|
||||
ledger->reset();
|
||||
wallet->reset();
|
||||
}
|
|
@ -50,6 +50,7 @@ protected:
|
|||
Q_INVOKABLE void setPassphrase(const QString& passphrase);
|
||||
Q_INVOKABLE void getPassphraseSetupStatus();
|
||||
Q_INVOKABLE void getKeyFilePathIfExists();
|
||||
Q_INVOKABLE void reset();
|
||||
};
|
||||
|
||||
#endif // hifi_QmlCommerce_h
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "Wallet.h"
|
||||
#include "Application.h"
|
||||
#include "ui/ImageProvider.h"
|
||||
#include "scripting/HMDScriptingInterface.h"
|
||||
|
||||
#include <PathUtils.h>
|
||||
#include <OffscreenUi.h>
|
||||
|
@ -464,7 +465,9 @@ void Wallet::getSecurityImage() {
|
|||
}
|
||||
|
||||
// decrypt and return
|
||||
if (decryptFile(imageFilePath(), &data, &dataLen)) {
|
||||
QString filePath(imageFilePath());
|
||||
QFileInfo fileInfo(filePath);
|
||||
if (fileInfo.exists() && decryptFile(filePath, &data, &dataLen)) {
|
||||
// create the pixmap
|
||||
_securityImage = new QPixmap();
|
||||
_securityImage->loadFromData(data, dataLen, "jpg");
|
||||
|
@ -488,3 +491,24 @@ void Wallet::sendKeyFilePathIfExists() {
|
|||
emit keyFilePathIfExistsResult("");
|
||||
}
|
||||
}
|
||||
|
||||
void Wallet::reset() {
|
||||
_publicKeys.clear();
|
||||
|
||||
delete _securityImage;
|
||||
_securityImage = nullptr;
|
||||
|
||||
// tell the provider we got nothing
|
||||
updateImageProvider();
|
||||
delete _passphrase;
|
||||
|
||||
// for now we need to maintain the hard-coded passphrase.
|
||||
// FIXME: remove this line as part of wiring up the passphrase
|
||||
// and probably set it to nullptr
|
||||
_passphrase = new QString("pwd");
|
||||
|
||||
QFile keyFile(keyFilePath());
|
||||
QFile imageFile(imageFilePath());
|
||||
keyFile.remove();
|
||||
imageFile.remove();
|
||||
}
|
||||
|
|
|
@ -40,6 +40,8 @@ public:
|
|||
void setPassphrase(const QString& passphrase);
|
||||
QString* getPassphrase() { return _passphrase; }
|
||||
|
||||
void reset();
|
||||
|
||||
signals:
|
||||
void securityImageResult(bool exists) ;
|
||||
void keyFilePathIfExistsResult(const QString& path);
|
||||
|
|
|
@ -18,10 +18,25 @@ const QString ImageProvider::PROVIDER_NAME = "security";
|
|||
QReadWriteLock ImageProvider::_rwLock;
|
||||
QPixmap* ImageProvider::_securityImage = nullptr;
|
||||
|
||||
void ImageProvider::setSecurityImage(QPixmap* pixmap) {
|
||||
ImageProvider::~ImageProvider() {
|
||||
QWriteLocker lock(&_rwLock);
|
||||
if (_securityImage) {
|
||||
delete _securityImage;
|
||||
_securityImage = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void ImageProvider::setSecurityImage(const QPixmap* pixmap) {
|
||||
// no need to delete old one, that is managed by the wallet
|
||||
QWriteLocker lock(&_rwLock);
|
||||
_securityImage = pixmap;
|
||||
if (_securityImage) {
|
||||
delete _securityImage;
|
||||
}
|
||||
if (pixmap) {
|
||||
_securityImage = new QPixmap(*pixmap);
|
||||
} else {
|
||||
_securityImage = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
QPixmap ImageProvider::requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) {
|
||||
|
|
|
@ -20,10 +20,10 @@ public:
|
|||
static const QString PROVIDER_NAME;
|
||||
|
||||
ImageProvider() : QQuickImageProvider(QQuickImageProvider::Pixmap) {}
|
||||
|
||||
virtual ~ImageProvider();
|
||||
QPixmap requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) override;
|
||||
|
||||
void setSecurityImage(QPixmap* pixmap);
|
||||
void setSecurityImage(const QPixmap* pixmap);
|
||||
protected:
|
||||
static QReadWriteLock _rwLock;
|
||||
static QPixmap* _securityImage;
|
||||
|
|
|
@ -70,6 +70,10 @@
|
|||
case 'maybeEnableHmdPreview':
|
||||
Menu.setIsOptionChecked("Disable Preview", isHmdPreviewDisabled);
|
||||
break;
|
||||
case 'walletReset':
|
||||
onButtonClicked();
|
||||
onButtonClicked();
|
||||
break;
|
||||
default:
|
||||
print('Unrecognized message from QML:', JSON.stringify(message));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue