Skip to content

Commit

Permalink
1.9.39
Browse files Browse the repository at this point in the history
  • Loading branch information
tongvanlinh committed Oct 23, 2024
1 parent ee8f007 commit d29cb30
Show file tree
Hide file tree
Showing 23 changed files with 527 additions and 29 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.38)
project(Nunchuk VERSION 1.9.39)
else()
project(nunchuk-qt VERSION 1.9.38)
project(nunchuk-qt VERSION 1.9.39)
endif()

set( CMAKE_CXX_STANDARD 20 )
Expand Down
10 changes: 10 additions & 0 deletions Images/wallet-dark-disabled.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions Models/Commons/Slugs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,8 @@ bool Slugs::isHoneyBadgerPlus() const
{
return slugs().contains("honey_badger_plus_testnet") || slugs().contains("honey_badger_plus");
}

bool Slugs::isDraftWallet() const
{
return false;
}
2 changes: 2 additions & 0 deletions Models/Commons/Slugs.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Slugs
virtual bool isPremierGroup() const;
virtual bool isGroupWallet() const;
virtual bool isUserWallet() const;

virtual bool isDraftWallet() const;
};

#endif // SLUGS_H
20 changes: 15 additions & 5 deletions Models/Premiums/QAssistedDraftWallets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,13 @@ bool QAssistedDraftWallets::RequestAddOrUpdateAKeyToDraftWallet(StructAddHardwar
ret = Draco::instance()->assistedWalletAddKey(hardware.mRequestId, data, isDuplicateKey, error_msg);
DBG_INFO << data << ret << isDuplicateKey;
} else {
ret = Byzantine::instance()->DraftWalletAddKey(hardware.mGroupId, hardware.mRequestId, data, isDuplicateKey, error_msg);
DBG_INFO << data << ret << error_msg << isDuplicateKey;
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;
}
if (ret) {
if (auto dashboard = QGroupWallets::instance()->dashboardInfoPtr()) {
dashboard->GetAlertsInfo();
Expand Down Expand Up @@ -222,8 +227,13 @@ bool QAssistedDraftWallets::RequestAddOrUpdateReuseKeyToDraftWallet(StructAddHar
DBG_INFO << data << ret << isDuplicateKey;
}
else {
ret = Byzantine::instance()->DraftWalletAddKey(hardware.mGroupId, hardware.mRequestId, data, isDuplicateKey, error_msg);
DBG_INFO << data << ret << error_msg << isDuplicateKey;
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;
}
if (ret) {
if (auto dashboard = QGroupWallets::instance()->dashboardInfoPtr()) {
dashboard->GetAlertsInfo();
Expand Down Expand Up @@ -329,7 +339,7 @@ int QAssistedDraftWallets::reuseKeyGetCurrentIndex(const QString &xfp)
ENUNCHUCK::AddressType::NATIVE_SEGWIT,
msg);
if((int)EWARNING::WarningType::NONE_MSG != msg.type()){
AppModel::instance()->showToast(msg.code(), msg.what(), EWARNING::WarningType::EXCEPTION_MSG);
DBG_INFO << msg.code() << msg.what();
}
return ret;
}
Expand Down
12 changes: 12 additions & 0 deletions Models/Premiums/QBasePremium.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Premiums/QInheritancePlan.h"
#include "Premiums/QRecurringPayment.h"
#include "Premiums/QWalletServicesTag.h"
#include "Premiums/QUserWallets.h"

QBasePremium::QBasePremium(WalletId wallet_id)
:m_wallet_id(wallet_id)
Expand Down Expand Up @@ -79,3 +80,14 @@ QStringList QBasePremium::slugs() const
{
return walletInfoPtr() ? walletInfoPtr()->slugs() : QStringList();
}

bool QBasePremium::isDraftWallet() const
{
auto dash = dynamic_cast<const QGroupDashboard*>(this);
if (dash) {
if (auto draft = QUserWallets::instance()->dashboardInfoPtr()) {
return qUtils::strCompare(dash->groupId(), draft->groupId());
}
}
return false;
}
1 change: 1 addition & 0 deletions Models/Premiums/QBasePremium.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class QBasePremium : public QObject, public Slugs
virtual QRecurringPaymentPtr recurringPaymentPtr() const;
virtual QWalletServicesTagPtr servicesTagPtr() const;
QStringList slugs() const final;
bool isDraftWallet() const final;
private:
WalletId m_wallet_id;
};
Expand Down
40 changes: 32 additions & 8 deletions Models/Premiums/QGroupDashboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ QString QGroupDashboard::userEmail() const

QVariantList QGroupDashboard::members() const
{
if (isDraftWallet()) {
return {};
}
return groupInfo()["members"].toArray().toVariantList();
}

Expand Down Expand Up @@ -165,7 +168,7 @@ QJsonObject QGroupDashboard::walletJson() const

void QGroupDashboard::GetMemberInfo()
{
if (isUserWallet() || isReplaced()) return;
if (isUserWallet() || isReplaced() || isDraftWallet()) return;
QJsonObject output;
QString error_msg = "";
bool ret = Byzantine::instance()->GetOneGroupWallets(groupId(), output, error_msg);
Expand All @@ -180,7 +183,10 @@ void QGroupDashboard::GetAlertsInfo()
QJsonObject output;
QString error_msg = "";
bool ret {false};
if (isUserWallet()) {
if (isDraftWallet()) {
ret = Draco::instance()->DraftWalletGetAlerts(output, error_msg);
}
else if (isUserWallet()) {
ret = Draco::instance()->GetAlerts(wallet_id(), output, error_msg);
}
else {
Expand Down Expand Up @@ -216,7 +222,10 @@ bool QGroupDashboard::MarkAlertAsRead(const QString &alert_id)
QJsonObject output;
QString error_msg = "";
bool ret {false};
if (isUserWallet()) {
if (isDraftWallet()) {
ret = Draco::instance()->DraftWalletMarkAnAlertAsRead(alert_id, output, error_msg);
}
else if (isUserWallet()) {
ret = Draco::instance()->MarkAlertAsRead(wallet_id(), alert_id, output, error_msg);
}
else {
Expand All @@ -237,7 +246,10 @@ bool QGroupDashboard::DismissAlert(const QString &alert_id)
QJsonObject output;
QString error_msg = "";
bool ret {false};
if (isUserWallet()) {
if (isDraftWallet()) {
ret = Draco::instance()->DraftWalletDismissAnAlert(alert_id, output, error_msg);
}
else if (isUserWallet()) {
ret = Draco::instance()->DismissAlert(wallet_id(), alert_id, output, error_msg);
}
else {
Expand All @@ -262,7 +274,9 @@ void QGroupDashboard::GetWalletInfo()
QJsonObject output;
QString error_msg = "";
bool ret {false};
if (isUserWallet()) {
if (isDraftWallet()) {

} else if (isUserWallet()) {
ret = Draco::instance()->assistedWalletGetInfo(wallet_id(), output, error_msg);
} else {
ret = Byzantine::instance()->GetCurrentGroupWallet(groupId(), output, error_msg);
Expand Down Expand Up @@ -301,10 +315,14 @@ void QGroupDashboard::checkInheritanceWallet()

void QGroupDashboard::GetDraftWalletInfo()
{
if (isUserWallet()) return;
QJsonObject output;
QString error_msg = "";
bool ret = Byzantine::instance()->GetCurrentGroupDraftWallet(groupId(), output, error_msg);
bool ret {false};
if (isDraftWallet()) {
ret = Draco::instance()->DraftWalletGetCurrent(output, error_msg);
} else if (!isUserWallet()){
ret = Byzantine::instance()->GetCurrentGroupDraftWallet(groupId(), output, error_msg);
}
if (ret) {
QJsonObject draft_wallet = output["draft_wallet"].toObject();
UpdateKeys(draft_wallet);
Expand Down Expand Up @@ -560,6 +578,7 @@ bool QGroupDashboard::canEntryClickAlert()
return true;
}
}
case AlertEnum::E_Alert_t::WALLET_PENDING:
case AlertEnum::E_Alert_t::GROUP_WALLET_PENDING:{
QtConcurrent::run([this]() {
GetDraftWalletInfo();
Expand Down Expand Up @@ -856,7 +875,12 @@ void QGroupDashboard::byzantineRoomDeleted(QString room_id, QString group_id)

void QGroupDashboard::requestShowLetAddYourKeys()
{
setFlow((int)AlertEnum::E_Alert_t::GROUP_WALLET_PENDING);
if (isDraftWallet()) {
setFlow((int)AlertEnum::E_Alert_t::WALLET_PENDING);
}
else {
setFlow((int)AlertEnum::E_Alert_t::GROUP_WALLET_PENDING);
}
QEventProcessor::instance()->sendEvent(E::EVT_SHOW_GROUP_WALLET_CONFIG_REQUEST);
}

Expand Down
21 changes: 19 additions & 2 deletions Models/Premiums/QGroupWallets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "Chats/ClientController.h"
#include "QEventProcessor.h"
#include "ViewsEnums.h"
#include "Premiums/QUserWallets.h"

QGroupWallets::QGroupWallets()
: QAssistedDraftWallets(GROUP_WALLET)
Expand Down Expand Up @@ -57,18 +58,25 @@ void QGroupWallets::GetAllGroups()
if(!CLIENT_INSTANCE->isNunchukLoggedIn()){
return;
}
QUserWallets::instance()->GetDraftWallet();
QtConcurrent::run([=, this]() {
QJsonObject output;
QString error_msg = "";
bool ret = Byzantine::instance()->GetAllGroupWallets(output, error_msg);
QJsonArray groupList;
auto draft = QUserWallets::instance()->dashboardInfoPtr();
if (draft) {
groupList.append(draft->groupInfo());
}
if (ret) {
QJsonArray groups = output["groups"].toArray();
for (auto v : groups) {
QJsonObject group = v.toObject();
groupList.append(group);
DBG_INFO << group["id"].toString() << group["status"].toString();
}
GetListAllRequestAddKey(groups);
emit dashboardList(groups);
emit dashboardList(groupList);
} else {
//Show error
DBG_INFO << error_msg;
Expand Down Expand Up @@ -110,7 +118,12 @@ void QGroupWallets::ResetGroupWallet()
if (!mDashboard) return;
QJsonObject output;
QString error_msg = "";
bool ret = Byzantine::instance()->ResetGroupWallet(mDashboard->groupId(), output, error_msg);
bool ret {false};
if (mDashboard->isDraftWallet()) {
ret = Draco::instance()->DraftWalletResetCurrent(output, error_msg);
} else {
ret = Byzantine::instance()->ResetGroupWallet(mDashboard->groupId(), output, error_msg);
}
if(ret){
GetAllGroups();
QString msg_name = QString("Wallet has been canceled");
Expand Down Expand Up @@ -139,6 +152,10 @@ void QGroupWallets::MakePendingDashboardList(const QJsonArray &groups)
else{ // status = "DELETED"
continue;
}
auto draft = QUserWallets::instance()->dashboardInfoPtr();
if (draft && draft->groupId() == group_id) {
dashboard = draft;
}
if(group_id != ""){
groupids.append(group_id);
if (!Contains(group_id)) {
Expand Down
50 changes: 50 additions & 0 deletions Models/Premiums/QUserWallets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ServiceSetting.h"
#include "nunchuckiface.h"
#include "ViewsEnums.h"
#include "ifaces/Servers/Draco.h"

QUserWallets::QUserWallets()
: QAssistedDraftWallets(USER_WALLET)
Expand All @@ -24,3 +25,52 @@ QUserWallets *QUserWallets::instance()
static QUserWallets mInstance;
return &mInstance;
}

void QUserWallets::GetDraftWallet()
{
QJsonObject output;
QString error_msg = "";
bool ret = Draco::instance()->DraftWalletGetCurrent(output, error_msg);
if (ret) {
QJsonObject draft_wallet = output["draft_wallet"].toObject();
if (draft_wallet.isEmpty()) {
mDashboard.clear();
}
else {
QJsonObject info;
info["status"] = "PENDING_WALLET";
info["id"] = draft_wallet["id"];
QJsonObject user;
DracoUser me = ClientController::instance()->getMe();
user["id"] = me.id;
user["name"] = me.name;
user["email"] = me.email;
user["avatar"] = me.avatar;
user["chat_id"] = me.chat_id;
QJsonObject member;
member["user"] = user;
member["status"] = "ACTIVE";
member["role"] = "MASTER";
QJsonArray members;
members.append(member);
info["members"] = members;
QGroupDashboardPtr dashboard = QGroupDashboardPtr(new QGroupDashboard(""));
dashboard->setGroupInfo(info);
DBG_INFO << info;
mDashboard = dashboard;
}
}
}

QGroupDashboardPtr QUserWallets::dashboardInfoPtr()
{
return mDashboard;
}

bool QUserWallets::hasDraftWallet(const QString& group_id)
{
if (!mDashboard.isNull() && mDashboard->groupId() == group_id) {
return true;
}
return false;
}
8 changes: 6 additions & 2 deletions Models/Premiums/QUserWallets.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "TypeDefine.h"
#include "Servers/Draco.h"
#include "Premiums/QAssistedDraftWallets.h"
#include "Premiums/QGroupDashboard.h"

class QUserWallets : public QAssistedDraftWallets
{
Expand All @@ -35,9 +36,12 @@ class QUserWallets : public QAssistedDraftWallets
QUserWallets();
~QUserWallets();
static QUserWallets *instance();
private:

void GetDraftWallet();

QGroupDashboardPtr dashboardInfoPtr();
bool hasDraftWallet(const QString& group_id);
private:
QGroupDashboardPtr mDashboard {};
};

#endif // QUSERWALLETS_H
2 changes: 1 addition & 1 deletion Qml/Components/customizes/Buttons/QIconButton.qml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ QBaseButton {
id: idIcon
width: iconSize
height: iconSize
icons: icon !== "" ? [icon, icon, icon, icon] : icons
icons: icon !== "" ? [icon, icon, icon, icon] : idBtn.icons
anchors.centerIn: parent
scale: btnMouse.pressed ? 0.9 : 1
transformOrigin: Item.Center
Expand Down
4 changes: 3 additions & 1 deletion Qml/Components/customizes/QHomePendingWallet.qml
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,13 @@ Rectangle {
}
}
}

QIconButton {
width: 48
height: 48
bgColor: "#F5F5F5"
icon: "qrc:/Images/Images/OnlineMode/wallet-dark.png"
enabled: !("PENDING_WALLET" === pendingDashboard.groupStatus)
icons: ["wallet-dark.svg", "wallet-dark.svg", "wallet-dark-disabled.svg", "wallet-dark.svg"]
onClicked: {
// FIXME GOTO WALLET INFO
dashboardInfo.isShowDashBoard = false
Expand Down
2 changes: 1 addition & 1 deletion Qml/Components/customizes/Signers/QAddRequestKey.qml
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ Item {
anchors.verticalCenter: parent.verticalCenter
horizontalAlignment: Text.AlignLeft
verticalAlignment: Text.AlignVCenter
font.pixelSize: 12
font.pixelSize: 16
}
}
QBadge {
Expand Down
Loading

0 comments on commit d29cb30

Please sign in to comment.