Skip to content

Commit

Permalink
1.9.40
Browse files Browse the repository at this point in the history
  • Loading branch information
tongvanlinh committed Nov 13, 2024
1 parent d29cb30 commit 9c2533f
Show file tree
Hide file tree
Showing 34 changed files with 905 additions and 197 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
cmake_minimum_required( VERSION 3.1 )
#set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14" CACHE STRING "Minimum OS X deployment version")
if(UNIX AND APPLE)
project(Nunchuk VERSION 1.9.39)
project(Nunchuk VERSION 1.9.40)
else()
project(nunchuk-qt VERSION 1.9.39)
project(nunchuk-qt VERSION 1.9.40)
endif()

set( CMAKE_CXX_STANDARD 20 )
Expand Down
8 changes: 6 additions & 2 deletions Models/Chats/ClientController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ void ClientController::setConnection(Connection *c)
}
emit connectionChanged();
connectSingleShot(m_connection.data(), &Connection::connected, this, [this]{
connection()->loadState();
connection()->sync();
try {
connection()->loadState();
connection()->sync();
} catch (const std::exception& e) {
DBG_INFO << "ClientController::setConnection::connected" << e.what();
}
connect(m_connection->user(), &User::defaultAvatarChanged, this, &ClientController::onUserAvatarChanged );
connect(m_connection->user(), &User::defaultNameChanged, this, &ClientController::onUserDisplaynameChanged );
connectSingleShot(m_connection.data(), &Connection::syncDone, this, [this] {
Expand Down
12 changes: 7 additions & 5 deletions Models/Chats/QNunchukRoomModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,15 +346,15 @@ void QNunchukRoom::slotFinishedDownloadTransaction(nunchuk::RoomTransaction room
rawtx.data()->setRoomId(id());
rawtx.data()->setInitEventId(QString::fromStdString(room_tx.get_init_event_id()));
target.data()->setTransaction(rawtx);
if(conversation()){
conversation()->updateTransaction(cons, target);
setPinTransaction(conversation()->pinTransaction());
}
}
}
if(!isDownloaded()){
startGetPendingTxs();
}
if(conversation()){
conversation()->updateTransaction(cons, target);
setPinTransaction(conversation()->pinTransaction());
}
if(AppModel::instance()->transactionInfo() && target.data()->transaction() && (qUtils::strCompare(QString::fromStdString(room_tx.get_init_event_id()), target.data()->transaction()->initEventId())))
{
AppModel::instance()->setTransactionInfo(target.data()->transactionPtr());
Expand Down Expand Up @@ -889,7 +889,9 @@ void QNunchukRoom::downloadTransactionThread(Conversation cons, const QString &r
nunchuk::Transaction tx = bridge::nunchukGetOriginTransaction(QString::fromStdString(room_tx.get_wallet_id()),
QString::fromStdString(room_tx.get_tx_id()),
txWarning);
emit signalFinishedDownloadTransaction(room_tx, tx, cons);
if((int)EWARNING::WarningType::NONE_MSG == txWarning.type() && tx.get_txid() != ""){
emit signalFinishedDownloadTransaction(room_tx, tx, cons);
}
}
}
});
Expand Down
67 changes: 54 additions & 13 deletions Models/Premiums/QAssistedDraftWallets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,21 @@ bool QAssistedDraftWallets::RequestAddOrUpdateAKeyToDraftWallet(StructAddHardwar
data["xpub"] = single->xpub();
data["pubkey"] = single->publickey();
data["type"] = qUtils::GetSignerTypeString(single->singleSigner().get_type());
auto dash = QGroupWallets::instance()->GetDashboard(hardware.mGroupId);
if (dash) {
if (dash->allowInheritance()) { // Request from Alert DashBoard
if (dash->nInfo() == 4 && hardware.mKeyIndex == 0) {
tags.append("INHERITANCE");
}
else if (dash->nInfo() == 5 && (hardware.mKeyIndex == 0 || hardware.mKeyIndex == 1)) {
tags.append("INHERITANCE");
}
}
}
if (hardware.mTags.contains("INHERITANCE") && !tags.contains("INHERITANCE")) { // Request receive from Mobile Banner
tags.append("INHERITANCE");
}
data["name"] = tags.contains("INHERITANCE") ? data["name"].toString() + "(inh.)" : data["name"].toString();
data["tags"] = tags;
data["tapsigner"] = {};
if (hardware.mKeyIndex >= 0) {
Expand All @@ -153,19 +168,19 @@ bool QAssistedDraftWallets::RequestAddOrUpdateAKeyToDraftWallet(StructAddHardwar
else {
data["key_index"] = {};
}
DBG_INFO << data;
bool isDuplicateKey {false};
bool ret {false};
QString error_msg;
if (hardware.mGroupId.isEmpty()) {
ret = Draco::instance()->assistedWalletAddKey(hardware.mRequestId, data, isDuplicateKey, error_msg);
DBG_INFO << data << ret << isDuplicateKey;
DBG_INFO << ret << isDuplicateKey;
} else {
auto dash = QGroupWallets::instance()->GetDashboard(hardware.mGroupId);
if (dash && dash->isDraftWallet()) {
ret = Draco::instance()->assistedWalletAddKey(hardware.mRequestId, data, isDuplicateKey, error_msg);
} else {
ret = Byzantine::instance()->DraftWalletAddKey(hardware.mGroupId, hardware.mRequestId, data, isDuplicateKey, error_msg);
DBG_INFO << data << ret << error_msg << isDuplicateKey;
DBG_INFO << ret << error_msg << isDuplicateKey;
}
if (ret) {
if (auto dashboard = QGroupWallets::instance()->dashboardInfoPtr()) {
Expand Down Expand Up @@ -211,6 +226,21 @@ bool QAssistedDraftWallets::RequestAddOrUpdateReuseKeyToDraftWallet(StructAddHar
data["xpub"] = QString::fromStdString(keyresued.get_xpub());
data["pubkey"] = QString::fromStdString(keyresued.get_public_key());
data["type"] = qUtils::GetSignerTypeString(keyresued.get_type());
auto dash = QGroupWallets::instance()->GetDashboard(hardware.mGroupId);
if (dash) {
if (dash->allowInheritance()) { // Request from Alert Dasboard
if (dash->nInfo() == 4 && hardware.mKeyIndex == 0) {
tags.append("INHERITANCE");
}
else if (dash->nInfo() == 5 && (hardware.mKeyIndex == 0 || hardware.mKeyIndex == 1)) {
tags.append("INHERITANCE");
}
}
}
if (hardware.mTags.contains("INHERITANCE") && !tags.contains("INHERITANCE")) { // Request receive from Mobile Banner
tags.append("INHERITANCE");
}
data["name"] = tags.contains("INHERITANCE") ? data["name"].toString() + "(inh.)" : data["name"].toString();
data["tags"] = tags;
data["tapsigner"] = {};
if (hardware.mKeyIndex >= 0) {
Expand All @@ -219,20 +249,21 @@ bool QAssistedDraftWallets::RequestAddOrUpdateReuseKeyToDraftWallet(StructAddHar
else {
data["key_index"] = {};
}
DBG_INFO << data;
bool isDuplicateKey {false};
bool ret {false};
QString error_msg;
if (hardware.mGroupId.isEmpty()) {
ret = Draco::instance()->assistedWalletAddKey(hardware.mRequestId, data, isDuplicateKey, error_msg);
DBG_INFO << data << ret << isDuplicateKey;
DBG_INFO << ret << isDuplicateKey << "Honybadger/IronHand";
}
else {
auto dash = QGroupWallets::instance()->GetDashboard(hardware.mGroupId);
if (dash && dash->isDraftWallet()) {
ret = Draco::instance()->assistedWalletAddKey(hardware.mRequestId, data, isDuplicateKey, error_msg);
DBG_INFO << ret << isDuplicateKey << "Honybadger/IronHand";
} else {
ret = Byzantine::instance()->DraftWalletAddKey(hardware.mGroupId, hardware.mRequestId, data, isDuplicateKey, error_msg);
DBG_INFO << data << ret << error_msg << isDuplicateKey;
DBG_INFO << ret << error_msg << isDuplicateKey << "Not Honybadger/IronHand";
}
if (ret) {
if (auto dashboard = QGroupWallets::instance()->dashboardInfoPtr()) {
Expand Down Expand Up @@ -270,6 +301,10 @@ void QAssistedDraftWallets::addRequest(const QJsonArray &requests, const QString
hardware.mGroupId = group_id;
hardware.mRequestId = request_id;
hardware.mKeyIndex = key_index;
hardware.mTags.clear();
for (auto tag: tags) {
hardware.mTags.append(tag.toString());
}
m_requests.insert(key, hardware);
}
}
Expand Down Expand Up @@ -424,16 +459,25 @@ bool QAssistedDraftWallets::requestKeyReplacement(QSingleSignerPtr signer)
DBG_INFO << single->tag() << "tag:" << single->tag() << m_mode << hardware.mGroupId;
if (warningmsg.type() == (int)EWARNING::WarningType::NONE_MSG) {
QJsonArray tags;
if (!single->tag().isEmpty()) {
tags.append(single->tag());
if (!single->tags().isEmpty()) {
QStringList list = single->tags();
list.removeAll("INHERITANCE");
for (auto tag : list) {
tags.append(tag);
}
}

data["name"] = single->name() != "" ? single->name() : titleCase(single->tag());
data["xfp"] = single->masterFingerPrint();
data["derivation_path"] = single->derivationPath();
data["xpub"] = single->xpub();
data["pubkey"] = single->publickey();
data["type"] = qUtils::GetSignerTypeString(single->singleSigner().get_type());
auto dashboard = QGroupWallets::instance()->dashboardInfoPtr();
if (dashboard.isNull()) return false;
if (dashboard->isInheritance() || hardware.mTags.contains("INHERITANCE")) { // Request receive from Mobile Banner
tags.append("INHERITANCE");
}
data["name"] = tags.contains("INHERITANCE") ? data["name"].toString() + "(inh.)" : data["name"].toString();
data["tags"] = tags;
data["tapsigner"] = {};
if (hardware.mKeyIndex >= 0) {
Expand All @@ -442,10 +486,7 @@ bool QAssistedDraftWallets::requestKeyReplacement(QSingleSignerPtr signer)
else {
data["key_index"] = {};
}
bool ret {false};
if (auto dashboard = QGroupWallets::instance()->dashboardInfoPtr()) {
ret = dashboard->FinishKeyReplacement(data);
}
bool ret = dashboard->FinishKeyReplacement(data);
if (ret) {
AppModel::instance()->setAddSignerWizard(3);
return true;
Expand Down
1 change: 1 addition & 0 deletions Models/Premiums/QAssistedDraftWallets.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct StructAddHardware
QString mGroupId {};
QString mRequestId {};
int mKeyIndex {-1};
QStringList mTags {};
};
class QAssistedDraftWallets : public QSwitchAPI
{
Expand Down
24 changes: 21 additions & 3 deletions Models/Premiums/QGroupDashboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,11 @@ void QGroupDashboard::UpdateKeys(const QJsonObject &data)
obj["ourAccount"] = false;
if (our_id == added_by_user_id) {
obj["ourAccount"] = true;
WalletsMng->UpdateSigner(obj);
}
signers.append(obj);
}
emit WalletsMng->signalUpdateSigner();

for (QJsonValue js : signers) {
QJsonObject signer = js.toObject();
Expand Down Expand Up @@ -626,10 +628,11 @@ bool QGroupDashboard::canEntryClickAlert()
payload["keyname"] = signer["name"].toString();
bool is_inheritance = signer["tapsigner"].toObject()["is_inheritance"].toBool();
payload["is_inheritance"] = is_inheritance;
payload["key_index"] = signer["key_index"].toInt();
auto alert = alertJson();
alert["payload"] = payload;
setAlertId(alert);
return !is_inheritance;
return true;
}
default:
break;
Expand Down Expand Up @@ -884,6 +887,12 @@ void QGroupDashboard::requestShowLetAddYourKeys()
QEventProcessor::instance()->sendEvent(E::EVT_SHOW_GROUP_WALLET_CONFIG_REQUEST);
}

void QGroupDashboard::requestShowReplacementKey()
{
setFlow((int)AlertEnum::E_Alert_t::KEY_REPLACEMENT_PENDING);
QEventProcessor::instance()->sendEvent(E::EVT_SHOW_GROUP_WALLET_CONFIG_REQUEST);
}

bool QGroupDashboard::isDowngrade(QString email_or_username, QString roleNew)
{
QString roleOld = "";
Expand Down Expand Up @@ -1166,8 +1175,8 @@ bool QGroupDashboard::FinishKeyReplacement(const QJsonObject &requestBody)
else {
ret = Byzantine::instance()->ReplaceKey(groupId(), wallet_id(), xfp, verifyToken, requestBody, error_msg);
}
DBG_INFO << ret << error_msg << requestBody;
if(ret){
DBG_INFO << ret << error_msg;
// Handle preparing model here.
GetAlertsInfo();
GetHealthCheckInfo();
Expand All @@ -1181,14 +1190,23 @@ bool QGroupDashboard::FinishKeyReplacement(const QJsonObject &requestBody)
bool QGroupDashboard::canReplaceKey()
{
auto type = static_cast<AlertEnum::E_Alert_t>(alertJson()["type"].toInt());
DBG_INFO << alertJson();
if (type == AlertEnum::E_Alert_t::KEY_REPLACEMENT_PENDING) {
QJsonObject payload = alertJson()["payload"].toObject();
return payload["can_replace"].toBool();
}
return false;
}

bool QGroupDashboard::isInheritance()
{
auto type = static_cast<AlertEnum::E_Alert_t>(alertJson()["type"].toInt());
if (type == AlertEnum::E_Alert_t::KEY_REPLACEMENT_PENDING) {
QJsonObject payload = alertJson()["payload"].toObject();
return payload["is_inheritance"].toBool();
}
return false;
}

QVariantList QGroupDashboard::keys() const
{
return m_keys;
Expand Down
2 changes: 2 additions & 0 deletions Models/Premiums/QGroupDashboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ class QGroupDashboard : public QBasePremium
bool FinishKeyReplacement(const QJsonObject &requestBody);

bool canReplaceKey();
bool isInheritance();

bool canEntryClickAlert();

Expand Down Expand Up @@ -231,6 +232,7 @@ public slots:
void byzantineRoomDeleted(QString room_id, QString group_id);

void requestShowLetAddYourKeys();
void requestShowReplacementKey();
bool isDowngrade(QString email_or_username, QString roleNew);
private:
bool deviceExport(const QStringList tags, nunchuk::SignerType type);
Expand Down
6 changes: 6 additions & 0 deletions Models/Premiums/QUserWallets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ void QUserWallets::GetDraftWallet()
dashboard->setGroupInfo(info);
DBG_INFO << info;
mDashboard = dashboard;
QJsonArray signers = draft_wallet["signers"].toArray();
for (auto js : signers) {
QJsonObject signer = js.toObject();
WalletsMng->UpdateSigner(signer);
}
emit WalletsMng->signalUpdateSigner();
}
}
}
Expand Down
33 changes: 33 additions & 0 deletions Models/Premiums/QWalletManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ QWalletManagement::QWalletManagement()
{
QQmlEngine::setObjectOwnership(this, QQmlEngine::CppOwnership);
connect(this, &QWalletManagement::getListWalletFinish, this, &QWalletManagement::slotGetListWalletFinish, Qt::QueuedConnection);
connect(this, &QWalletManagement::signalUpdateSigner, this, &QWalletManagement::slotUpdateSigner, Qt::QueuedConnection);
}

QWalletManagement::~QWalletManagement()
Expand Down Expand Up @@ -270,6 +271,30 @@ void QWalletManagement::GetListWallet(int mode)
UpdateSyncWalletFlows();
}

void QWalletManagement::UpdateSigner(const QJsonObject &signer)
{
QJsonObject js_signer = signer;
QString xfp = js_signer["xfp"].toString();
QString name = js_signer["name"].toString();
bool is_visible = js_signer["is_visible"].toBool();
QJsonArray wtags = js_signer["tags"].toArray();
QWarningMessage msgIn;
nunchuk::MasterSigner master_signer = bridge::nunchukGetOriginMasterSigner(xfp, msgIn);
if (msgIn.type() == (int)EWARNING::WarningType::NONE_MSG) {
std::vector<nunchuk::SignerTag> tags; // get tags from api signer.tags
for (QJsonValue tag : wtags) {
QString js_tag = tag.toString();
tags.push_back(SignerTagFromStr(js_tag.toStdString()));
}
// Do update
master_signer.set_name(name.toStdString());
master_signer.set_tags(tags);
master_signer.set_visible(is_visible);
msgIn.resetWarningMessage();
bridge::UpdateMasterSigner(master_signer, msgIn);
}
}

void QWalletManagement::UpdateSyncWalletFlows()
{
QMap<QString, QJsonObject> server_signers;
Expand Down Expand Up @@ -723,3 +748,11 @@ void QWalletManagement::slotGetListWalletFinish()
QGroupWallets::instance()->findPermissionAccount();
AppModel::instance()->requestOnboarding();
}

void QWalletManagement::slotUpdateSigner()
{
QMasterSignerListModelPtr mastersigners = bridge::nunchukGetMasterSigners();
if(mastersigners){
AppModel::instance()->setMasterSignerList(mastersigners);
}
}
3 changes: 3 additions & 0 deletions Models/Premiums/QWalletManagement.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class QWalletManagement : public QObject
explicit QWalletManagement();
virtual ~QWalletManagement();
void GetListWallet(int mode);
void UpdateSigner(const QJsonObject &signer);
void UpdateSyncWalletFlows();
QString UpdateSyncWalletFlows(bool yes, bool no);
WalletIdList wallets() const;
Expand All @@ -38,8 +39,10 @@ class QWalletManagement : public QObject
int activeSize() const;
public slots:
void slotGetListWalletFinish();
void slotUpdateSigner();
signals:
void getListWalletFinish();
void signalUpdateSigner();
private:
QMap<QString, QString> mWallets;
QMap<QString, QJsonObject> mWalletsInfo;
Expand Down
2 changes: 1 addition & 1 deletion Models/Premiums/QWalletServicesTag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ int QWalletServicesTag::inheritanceDownloadBackup(const QString &magic, const QS
std::vector<unsigned char> base64vec(base64bin.begin(), base64bin.end());
QString key_name = key["key_name"].toString();
QString derivation_path = key["derivation_path"].toString();
auto master_signer_ptr = bridge::ImportTapsignerMasterSigner(base64vec, backup_key, key_name, false, msg);
auto master_signer_ptr = bridge::ImportBackupKey(base64vec, backup_key, key_name, false, msg);
if (master_signer_ptr) {
msg.resetWarningMessage();
auto master_signer = master_signer_ptr->originMasterSigner();
Expand Down
Loading

0 comments on commit 9c2533f

Please sign in to comment.