Fabcoin Core  0.16.2
P2P Digital Currency
addtokenpage.cpp
Go to the documentation of this file.
1 #include <addtokenpage.h>
2 #include <ui_addtokenpage.h>
3 #include <guiconstants.h>
4 #include <wallet/wallet.h>
5 #include <clientmodel.h>
6 #include <walletmodel.h>
7 #include <token.h>
8 #include <qvalidatedlineedit.h>
9 #include <contractabi.h>
10 #include <validation.h>
11 #include <addresstablemodel.h>
12 #include <optionsmodel.h>
13 #include <styleSheet.h>
14 
15 #include <QRegularExpressionValidator>
16 #include <QMessageBox>
17 
19  QWidget(parent),
20  ui(new Ui::AddTokenPage),
21  m_tokenABI(0),
22  m_model(0),
23  m_clientModel(0)
24 {
25  ui->setupUi(this);
26 
27  // Set stylesheet
28  SetObjectStyleSheet(ui->clearButton, StyleSheetNames::ButtonBlack);
29 
30  ui->labelDescription->setText(tr("(This is your wallet address which will be tied to the token for send/receive operations)"));
31  QFont font = QApplication::font();
32  font.setPointSizeF(font.pointSizeF() * 0.8);
33  ui->labelDescription->setFont(font);
34  ui->labelSpacer->setFont(font);
35 
36  m_tokenABI = new Token();
37 
38  connect(ui->lineEditContractAddress, SIGNAL(textChanged(const QString &)), this, SLOT(on_addressChanged()));
39  connect(ui->lineEditTokenName, SIGNAL(textChanged(const QString &)), SLOT(on_updateConfirmButton()));
40  connect(ui->lineEditTokenSymbol, SIGNAL(textChanged(const QString &)), SLOT(on_updateConfirmButton()));
41 
45  if(ui->lineEditSenderAddress->isEditable())
46  ((QValidatedLineEdit*)ui->lineEditSenderAddress->lineEdit())->setEmptyIsValid(false);
47  m_validTokenAddress = false;
48 }
49 
51 {
52  delete ui;
53 
54  if(m_tokenABI)
55  delete m_tokenABI;
56  m_tokenABI = 0;
57 }
58 
60 {
61  m_clientModel = clientModel;
62  if (m_clientModel)
63  {
64  connect(m_clientModel, SIGNAL(tipChanged()), this, SLOT(on_numBlocksChanged()));
66  }
67 }
68 
70 {
71  ui->lineEditContractAddress->setText("");
72  ui->lineEditTokenName->setText("");
73  ui->lineEditTokenSymbol->setText("");
74  ui->lineEditDecimals->setText("");
75  ui->lineEditSenderAddress->setCurrentIndex(-1);
76 }
77 
79 {
80  m_model = _model;
82  connect(m_model->getOptionsModel(), SIGNAL(zeroBalanceAddressTokenChanged(bool)), this, SLOT(on_zeroBalanceAddressToken(bool)));
83 }
84 
86 {
87  clearAll();
88 }
89 
91 {
93  {
94  CTokenInfo tokenInfo;
95  tokenInfo.strContractAddress = ui->lineEditContractAddress->text().toStdString();
96  tokenInfo.strTokenName = ui->lineEditTokenName->text().toStdString();
97  tokenInfo.strTokenSymbol = ui->lineEditTokenSymbol->text().toStdString();
98  tokenInfo.nDecimals = ui->lineEditDecimals->text().toInt();
99  tokenInfo.strSenderAddress = ui->lineEditSenderAddress->currentText().toStdString();
100 
101  if(m_model)
102  {
103  if(!m_model->isMineAddress(tokenInfo.strSenderAddress))
104  {
105  QString symbol = QString::fromStdString(tokenInfo.strTokenSymbol);
106  QString address = QString::fromStdString(tokenInfo.strSenderAddress);
107  QString message = tr("The %1 address \"%2\" is not yours, please change it to new one.\n").arg(symbol, address);
108  QMessageBox::warning(this, tr("Invalid token address"), message);
109  }
110  else if(m_model->existTokenEntry(tokenInfo))
111  {
112  QMessageBox::information(this, tr("Token exist"), tr("The token already exist with the specified contract and sender addresses."));
113  }
114  else
115  {
116  m_model->addTokenEntry(tokenInfo);
117 
118  clearAll();
119 
120  if(!fLogEvents)
121  {
122  QMessageBox::information(this, tr("Log events"), tr("Enable log events from the option menu in order to receive token transactions."));
123  }
124  }
125  }
126  }
127 }
128 
130 {
131  QString tokenAddress = ui->lineEditContractAddress->text();
132  if(m_tokenABI)
133  {
134  m_tokenABI->setAddress(tokenAddress.toStdString());
135  std::string name, symbol, decimals;
136  bool ret = m_tokenABI->name(name);
137  ret &= m_tokenABI->symbol(symbol);
138  ret &= m_tokenABI->decimals(decimals);
139  ui->lineEditTokenName->setText(QString::fromStdString(name));
140  ui->lineEditTokenSymbol->setText(QString::fromStdString(symbol));
141  ui->lineEditDecimals->setText(QString::fromStdString(decimals));
142  m_validTokenAddress = ret;
143  }
144  ui->confirmButton->setEnabled(m_validTokenAddress);
145 }
146 
148 {
150 }
151 
153 {
154  bool enabled = true;
155  if(ui->lineEditTokenName->text().isEmpty())
156  {
157  enabled = false;
158  }
159  if(ui->lineEditTokenSymbol->text().isEmpty())
160  {
161  enabled = false;
162  }
163  enabled &= m_validTokenAddress;
164  ui->confirmButton->setEnabled(enabled);
165 }
166 
168 {
169  QAbstractItemModel *addressTableModel = 0;
170  if(enable && m_model)
171  {
172  addressTableModel = m_model->getAddressTableModel();
173  }
174  ui->lineEditSenderAddress->setAddressTableModel(addressTableModel);
175 }
bool fLogEvents
Definition: validation.cpp:88
std::string strTokenSymbol
Definition: wallet.h:1302
#define SetObjectStyleSheet(object, name)
Definition: styleSheet.h:10
QLineEdit * lineEditDecimals
void setAddressColumn(int addressColumn)
void setTypeRole(int typeRole)
QPushButton * clearButton
void setAddressTableModel(QAbstractItemModel *addressTableModel)
void on_addressChanged()
std::string strSenderAddress
Definition: wallet.h:1304
bool decimals(std::string &result, bool sendTo=false)
Definition: token.cpp:343
QLineEdit * lineEditContractAddress
void setupUi(QWidget *AddTokenPage)
bool isMineAddress(const std::string &strAddress)
bool existTokenEntry(const CTokenInfo &token)
Line edit that can be marked as "invalid" to show input validation feedback.
Definition: token.h:32
AddressTableModel * getAddressTableModel()
void on_refresh()
on_refresh Refresh the list of addresses
void on_clearButton_clicked()
QPushButton * confirmButton
void setModel(WalletModel *_model)
WalletModel * m_model
Definition: addtokenpage.h:37
void on_numBlocksChanged()
bool name(std::string &result, bool sendTo=false)
Definition: token.cpp:264
bool m_validTokenAddress
Definition: addtokenpage.h:39
void on_zeroBalanceAddressToken(bool enable)
std::string strContractAddress
Definition: wallet.h:1300
void on_updateConfirmButton()
const char * name
Definition: rest.cpp:36
void setAddress(const std::string &address)
Definition: token.cpp:217
void on_confirmButton_clicked()
AddressTableModel * parent
bool isValidAddress()
Model for Fabcoin network client.
Definition: clientmodel.h:38
bool symbol(std::string &result, bool sendTo=false)
Definition: token.cpp:433
void setReceive(const QString &receive)
uint8_t nDecimals
Definition: wallet.h:1303
ClientModel * m_clientModel
Definition: addtokenpage.h:38
QLabel * labelDescription
Interface to Fabcoin wallet from Qt view code.
Definition: walletmodel.h:103
static const QString Receive
Specifies receive address.
virtual QString currentText() const
currentText Get the current text
QLineEdit * lineEditTokenName
Token * m_tokenABI
Definition: addtokenpage.h:36
Ui::AddTokenPage * ui
Definition: addtokenpage.h:35
struct evm_uint160be address(struct evm_env *env)
Definition: capi.c:13
void setClientModel(ClientModel *clientModel)
QLabel * labelSpacer
QLineEdit * lineEditTokenSymbol
bool addTokenEntry(const CTokenInfo &token)
bool bZeroBalanceAddressToken
Definition: wallet.cpp:46
Type of address (Send or Receive)
AddressField * lineEditSenderAddress
AddTokenPage(QWidget *parent=0)
OptionsModel * getOptionsModel()
std::string strTokenName
Definition: wallet.h:1301