Skip to content

Commit

Permalink
Refactored communication between client and handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalius-parubochyi-vakoms committed Nov 15, 2018
1 parent ee3e334 commit 7649ebc
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 40 deletions.
4 changes: 2 additions & 2 deletions GraftMobileClient/core/api/graftwallethandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ public slots:

signals:
void saleDetailsReceived(int result, const QString &details);
void rejectPayReceived(int result);
void payReceived(int result);
void payStatusReceived(int result, int status);
void rejectPayReceived(bool result);
void payStatusReceived(bool result);
};

#endif // GRAFTWALLETHANDLER_H
38 changes: 36 additions & 2 deletions GraftMobileClient/core/api/v1/graftwallethandlerv1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
GraftWalletHandlerV1::GraftWalletHandlerV1(const QString &dapiVersion, const QStringList addresses,
QObject *parent)
: GraftWalletHandler(parent)
,mBlockNumber(0)
{
mApi = new GraftWalletAPIv1(addresses, dapiVersion, this);
connect(mApi, &GraftWalletAPIv1::createAccountReceived,
Expand All @@ -21,10 +22,10 @@ GraftWalletHandlerV1::GraftWalletHandlerV1(const QString &dapiVersion, const QSt
connect(mApi, &GraftWalletAPIv1::getPOSDataReceived,
this, &GraftWalletHandlerV1::saleDetailsReceived);
connect(mApi, &GraftWalletAPIv1::rejectPayReceived,
this, &GraftWalletHandlerV1::rejectPayReceived);
this, &GraftWalletHandlerV1::receiveRejectPay);
connect(mApi, &GraftWalletAPIv1::payReceived, this, &GraftWalletHandlerV1::payReceived);
connect(mApi, &GraftWalletAPIv1::getPayStatusReceived,
this, &GraftWalletHandlerV1::payStatusReceived);
this, &GraftWalletHandlerV1::receivePayStatus);
connect(mApi, &GraftWalletAPIv1::error, this, &GraftWalletHandlerV1::errorReceived);
}

Expand Down Expand Up @@ -130,6 +131,8 @@ void GraftWalletHandlerV1::pay(const QString &pid, const QString &address, doubl
{
if (mApi)
{
mLastPID = pid;
mBlockNumber = blockNumber;
mApi->pay(pid, address, amount, blockNumber);
}
}
Expand All @@ -143,6 +146,37 @@ void GraftWalletHandlerV1::payStatus(const QString &pid, int blockNumber)
}
}

void GraftWalletHandlerV1::receiveRejectPay(int result)
{
emit rejectPayReceived(result == 0);
}

void GraftWalletHandlerV1::receivePayStatus(int result, int status)
{
if (result == 0)
{
switch (status) {
case GraftWalletAPIv1::StatusProcessing:
payStatus(mLastPID, mBlockNumber);
break;
case GraftWalletAPIv1::StatusApproved:
emit payStatusReceived(true);
break;
case GraftWalletAPIv1::StatusNone:
case GraftWalletAPIv1::StatusFailed:
case GraftWalletAPIv1::StatusPOSRejected:
case GraftWalletAPIv1::StatusWalletRejected:
default:
emit payStatusReceived(false);
break;
}
}
else
{
emit payStatusReceived(false);
}
}

void GraftWalletHandlerV1::receiveBalance(double balance, double unlockedBalance)
{
QTimer::singleShot(20000, this, &GraftWalletHandlerV1::updateBalance);
Expand Down
4 changes: 4 additions & 0 deletions GraftMobileClient/core/api/v1/graftwallethandlerv1.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ public slots:
void payStatus(const QString &pid, int blockNumber) override;

private slots:
void receiveRejectPay(int result);
void receivePayStatus(int result, int status);
void receiveBalance(double balance, double unlockedBalance);

private:
GraftWalletAPIv1 *mApi;
QString mLastPID;
int mBlockNumber;
};

#endif // GRAFTWALLETHANDLERV1_H
9 changes: 7 additions & 2 deletions GraftMobileClient/core/api/v2/graftwallethandlerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GraftWalletHandlerV2::GraftWalletHandlerV2(const QString &dapiVersion, const QSt
connect(mApi, &GraftWalletAPIv2::saleDetailsReceived,
this, &GraftWalletHandlerV2::receiveSaleDetails);
connect(mApi, &GraftWalletAPIv2::rejectPayReceived,
this, &GraftWalletHandlerV2::rejectPayReceived);
this, &GraftWalletHandlerV2::receiveRejectPay);
connect(mApi, &GraftWalletAPIv2::payReceived, this, &GraftWalletHandlerV2::payReceived);
connect(mApi, &GraftWalletAPIv2::payStatusReceived,
this, &GraftWalletHandlerV2::receivePayStatus);
Expand Down Expand Up @@ -228,6 +228,11 @@ void GraftWalletHandlerV2::sendPay(bool result)

}

void GraftWalletHandlerV2::receiveRejectPay(int result)
{
emit rejectPayReceived(result == 0);
}

void GraftWalletHandlerV2::receivePayStatus(int status)
{
switch (status) {
Expand Down Expand Up @@ -261,5 +266,5 @@ void GraftWalletHandlerV2::processPayResult(bool result)
mLastPID.clear();
mBlockNumber = 0;
}
emit payStatusReceived(0, result);
emit payStatusReceived(result);
}
1 change: 1 addition & 0 deletions GraftMobileClient/core/api/v2/graftwallethandlerv2.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ private slots:
void receiveSaleDetails(const QVector<QPair<QString, QString>> &authSample,
const QString &saleDetails);
void sendPay(bool result);
void receiveRejectPay(int result);
void receivePayStatus(int status);
void processPayResult(bool result);

Expand Down
33 changes: 1 addition & 32 deletions GraftMobileClient/core/graftwalletclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ void GraftWalletClient::receiveSaleDetails(int result, const QString &payDetails
emit saleDetailsReceived(isStatusOk);
}

void GraftWalletClient::receiveRejectPay(int result)
{
emit rejectPayReceived(result == 0);
}

void GraftWalletClient::receivePay(int result)
{
const bool isStatusOk = (result == 0);
Expand All @@ -99,32 +94,6 @@ void GraftWalletClient::receivePay(int result)
}
}

void GraftWalletClient::receivePayStatus(int result, int status)
{
if (result == 0)
{
switch (status) {
case GraftWalletAPIv1::StatusProcessing:
payStatus();
break;
case GraftWalletAPIv1::StatusApproved:
emit payStatusReceived(true);
break;
case GraftWalletAPIv1::StatusNone:
case GraftWalletAPIv1::StatusFailed:
case GraftWalletAPIv1::StatusPOSRejected:
case GraftWalletAPIv1::StatusWalletRejected:
default:
emit payStatusReceived(false);
break;
}
}
else
{
emit payStatusReceived(false);
}
}

void GraftWalletClient::changeGraftHandler()
{
if (mClientHandler)
Expand All @@ -150,7 +119,7 @@ void GraftWalletClient::changeGraftHandler()
connect(mClientHandler, &GraftWalletHandler::saleDetailsReceived,
this, &GraftWalletClient::receiveSaleDetails);
connect(mClientHandler, &GraftWalletHandler::rejectPayReceived,
this, &GraftWalletClient::receiveRejectPay);
this, &GraftWalletClient::rejectPayReceived);
connect(mClientHandler, &GraftWalletHandler::payStatusReceived,
this, &GraftWalletClient::payStatusReceived);
connect(mClientHandler, &GraftWalletHandler::errorReceived,
Expand Down
2 changes: 0 additions & 2 deletions GraftMobileClient/core/graftwalletclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ public slots:

private slots:
void receiveSaleDetails(int result, const QString &payDetails);
void receiveRejectPay(int result);
void receivePay(int result);
void receivePayStatus(int result, int status);

private:
void changeGraftHandler() override;
Expand Down

0 comments on commit 7649ebc

Please sign in to comment.