def set_money_text(self, params, currency): """ Set text from money parameters :param sakia.data.entities.BlockchainParameters params: Parameters of the currency :param str currency: The currency """ dt_dhms = timestamp_to_dhms(params.dt) if dt_dhms[0] > 0: dt_as_str = self.tr("{:} day(s) {:} hour(s)").format(*dt_dhms) else: dt_as_str = self.tr("{:} hour(s)").format(dt_dhms[1]) if dt_dhms[2] > 0 or dt_dhms[3] > 0: dt_dhms += ", {:} minute(s) and {:} second(s)".format(*dt_dhms[1:]) dt_reeval_dhms = timestamp_to_dhms(params.dt_reeval) dt_reeval_as_str = self.tr("{:} day(s) {:} hour(s)").format(*dt_reeval_dhms) # set infos in label self.label_money.setText( self.tr(""" <table cellpadding="5"> <tr><td align="right"><b>{:2.0%} / {:} days</b></td><td>{:}</td></tr> <tr><td align="right"><b>{:}</b></td><td>{:} {:}</td></tr> <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> <tr><td align="right"><b>{:2.0%}</b></td><td>{:}</td></tr> </table> """).format( params.c, QLocale().toString(params.dt / 86400, 'f', 2), self.tr('Fundamental growth (c)'), params.ud0, self.tr('Initial Universal Dividend UD(0) in'), currency, dt_as_str, self.tr('Time period between two UD'), dt_reeval_as_str, self.tr('Time period between two UD reevaluation'), params.median_time_blocks, self.tr('Number of blocks used for calculating median time'), params.avg_gen_time, self.tr('The average time in seconds for writing 1 block (wished time)'), params.dt_diff_eval, self.tr('The number of blocks required to evaluate again PoWMin value'), params.percent_rot, self.tr('The percent of previous issuers to reach for personalized difficulty') ) )
def money_text(self, params, currency): """ Set text from money parameters :param sakia.data.entities.BlockchainParameters params: Parameters of the currency :param str currency: The currency """ dt_dhms = timestamp_to_dhms(params.dt) if dt_dhms[0] > 0: dt_as_str = self.tr("{:} day(s) {:} hour(s)").format(*dt_dhms) else: dt_as_str = self.tr("{:} hour(s)").format(dt_dhms[1]) if dt_dhms[2] > 0 or dt_dhms[3] > 0: dt_dhms += ", {:} minute(s) and {:} second(s)".format(*dt_dhms[1:]) dt_reeval_dhms = timestamp_to_dhms(params.dt_reeval) dt_reeval_as_str = self.tr("{:} day(s) {:} hour(s)").format(*dt_reeval_dhms) # set infos in label return self.tr(""" <table cellpadding="5"> <tr><td align="right"><b>{:2.2%} / {:} days</b></td><td>{:}</td></tr> <tr><td align="right"><b>{:}</b></td><td>{:} {:}</td></tr> <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> <tr><td align="right"><b>{:2.0%}</b></td><td>{:}</td></tr> </table> """).format( params.c, QLocale().toString(params.dt / 86400, 'f', 2), self.tr('Fundamental growth (c)'), params.ud0, self.tr('Initial Universal Dividend UD(0) in'), currency, dt_as_str, self.tr('Time period between two UD'), dt_reeval_as_str, self.tr('Time period between two UD reevaluation'), params.median_time_blocks, self.tr('Number of blocks used for calculating median time'), params.avg_gen_time, self.tr('The average time in seconds for writing 1 block (wished time)'), params.dt_diff_eval, self.tr('The number of blocks required to evaluate again PoWMin value'), params.percent_rot, self.tr('The percent of previous issuers to reach for personalized difficulty') )
async def show_register_message(self, blockchain_parameters): """ :param sakia.data.entities.BlockchainParameters blockchain_parameters: :return: """ days, hours, minutes, seconds = timestamp_to_dhms(blockchain_parameters.idty_window) expiration_time_str = self.tr("{days} days, {hours}h and {min}min").format(days=days, hours=hours, min=minutes) dialog = QDialog(self) about_dialog = Ui_CongratulationPopup() about_dialog.setupUi(dialog) dialog.setWindowTitle("Registration") about_dialog.label.setText(self.tr(""" <p><b>Congratulations !</b><br> <br> You just published your identity to the network.<br> For your identity to be registered, you will need<br> <b>{certs} certifications</b> from members.<br> Once you got the required certifications, <br> you will be able to validate your registration<br> by <b>publishing your membership request !</b><br> Please notice that your identity document <br> <b>will expire in {expiration_time_str}.</b><br> If you failed to get {certs} certifications before this time, <br> the process will have to be restarted from scratch.</p> """.format(certs=blockchain_parameters.sig_qty, expiration_time_str=expiration_time_str))) await dialog_async_exec(dialog)
async def show_register_message(self, blockchain_parameters): """ :param sakia.data.entities.BlockchainParameters blockchain_parameters: :return: """ days, hours, minutes, seconds = timestamp_to_dhms( blockchain_parameters.idty_window) expiration_time_str = self.tr( "{days} days, {hours}h and {min}min").format(days=days, hours=hours, min=minutes) await QAsyncMessageBox.information( self, self.tr("Registration"), self.tr(""" <b>Congratulations !</b><br> <br> You just published your identity to the network.<br> For your identity to be registered, you will need <b>{certs} certifications</b> from members.<br> Once you got the required certifications, you will be able to validate your registration by <b>publishing your membership request !</b><br> Please notice that your identity document <b>will expire in {expiration_time_str}.</b> If you failed to get {certs} certifications before this time, the process will have to be restarted from scratch. """.format(certs=blockchain_parameters.sig_qty, expiration_time_str=expiration_time_str)))
def remaining_time(self): """ Get remaining time as a tuple to display :return: a tuple containing (days, hours, minutes, seconds) :rtype: tuple[int] """ parameters = self._blockchain_processor.parameters(self.connection.currency) blockchain_time = self._blockchain_processor.time(self.connection.currency) remaining_time = self._certifications_processor.cert_issuance_delay(self.connection.currency, self.connection.pubkey, parameters, blockchain_time) return timestamp_to_dhms(remaining_time)
def remaining_time(self): """ Get remaining time as a tuple to display :return: a tuple containing (days, hours, minutes, seconds) :rtype: tuple[int] """ parameters = self._blockchain_processor.parameters( self.connection.currency) blockchain_time = self._blockchain_processor.time( self.connection.currency) remaining_time = self._certifications_processor.cert_issuance_delay( self.connection.currency, self.connection.pubkey, parameters, blockchain_time) return timestamp_to_dhms(remaining_time)
async def licence_dialog(self, currency, params): dt_dhms = timestamp_to_dhms(params.dt) if dt_dhms[0] > 0: dt_as_str = self.tr("{:} day(s) {:} hour(s)").format(*dt_dhms) else: dt_as_str = self.tr("{:} hour(s)").format(dt_dhms[1]) if dt_dhms[2] > 0 or dt_dhms[3] > 0: dt_dhms += ", {:} minute(s) and {:} second(s)".format(*dt_dhms[1:]) dt_reeval_dhms = timestamp_to_dhms(params.dt_reeval) dt_reeval_as_str = self.tr("{:} day(s) {:} hour(s)").format(*dt_reeval_dhms) message_box = QMessageBox(self) message_box.setText("Do you recognize the terms of the following licence :") message_box.setInformativeText(""" {:} is being produced by a Universal Dividend (UD) for any human member, which is :<br/> <br/> <table cellpadding="5"> <tr><td align="right"><b>{:2.0%} / {:} days</b></td><td>{:}</td></tr> <tr><td align="right"><b>{:}</b></td><td>{:} {:}</td></tr> <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> </table> <br/> <br/> The parameters of the Web of Trust of {:} are :<br/> <table cellpadding="5"> <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> <tr><td align="right"><b>{:}</b></td><td>{:}</td></tr> </table> <br/> <br/> <b>By asking to join as member, you recognize that this is your unique account, and that you will only certify persons that you know well enough.</b> """.format( ROOT_SERVERS[currency]["display"], params.c, QLocale().toString(params.dt / 86400, 'f', 2), self.tr('Fundamental growth (c)'), params.ud0, self.tr('Initial Universal Dividend UD(0) in'), ROOT_SERVERS[currency]["display"], dt_as_str, self.tr('Time period between two UD'), dt_reeval_as_str, self.tr('Time period between two UD reevaluation'), ROOT_SERVERS[currency]["display"], QLocale().toString(params.sig_period / 86400, 'f', 2), self.tr('Minimum delay between 2 certifications (in days)'), QLocale().toString(params.sig_validity / 86400, 'f', 2), self.tr('Maximum age of a valid signature (in days)'), params.sig_qty, self.tr('Minimum quantity of signatures to be part of the WoT'), params.sig_stock, self.tr('Maximum quantity of active certifications made by member.'), params.sig_window, self.tr('Maximum delay a certification can wait before being expired for non-writing.'), params.xpercent, self.tr('Minimum percent of sentries to reach to match the distance rule'), params.ms_validity / 86400, self.tr('Maximum age of a valid membership (in days)'), params.step_max, self.tr('Maximum distance between each WoT member and a newcomer'), ) ) message_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No ) message_box.setDefaultButton(QMessageBox.No) return await dialog_async_exec(message_box)
def set_simple_informations(self, data, state): if state in (InformationsView.CommunityState.NOT_INIT, InformationsView.CommunityState.OFFLINE): self.label_currency.setText("""<html> <body> <p> <span style=" font-size:16pt; font-weight:600;">{currency}</span> </p> <p>{message}</p> </body> </html>""".format(currency=data['currency'], message=InformationsView.simple_message[state])) self.button_membership.hide() else: status_value = self.tr("Member") if data['membership_state'] else self.tr("Non-Member") if data['mstime'] > 0: membership_action_value = self.tr("Renew membership") status_info = "" membership_action_enabled = True elif data['membership_state']: membership_action_value = self.tr("Renew membership") status_info = "Your membership expired" membership_action_enabled = True else: membership_action_value = self.tr("Request membership") if data['nb_certs'] > data['nb_certs_required']: status_info = self.tr("Registration ready") membership_action_enabled = True else: status_info = self.tr("{0} more certifications required")\ .format(data['nb_certs_required'] - data['nb_certs']) membership_action_enabled = True if data['mstime'] > 0: days, hours, minutes, seconds = timestamp_to_dhms(data['mstime']) mstime_remaining_text = self.tr("Expires in ") if days > 0: mstime_remaining_text += "{days} days".format(days=days) else: mstime_remaining_text += "{hours} hours and {min} min.".format(hours=hours, min=minutes) else: mstime_remaining_text = self.tr("Expired or never published") status_color = '#00AA00' if data['membership_state'] else self.tr('#FF0000') description_currency = """<html> <body> <p> <span style=" font-size:16pt; font-weight:600;">{currency}</span> </p> <p>{nb_members} {members_label}</p> <p><span style="font-weight:600;">{monetary_mass_label}</span> : {monetary_mass}</p> <p><span style="font-weight:600;">{balance_label}</span> : {balance}</p> </body> </html>""".format(currency=data['currency'], nb_members=data['members_count'], members_label=self.tr("members"), monetary_mass_label=self.tr("Monetary mass"), monetary_mass=data['mass'], balance_label=self.tr("Balance"), balance=data['amount']) description_membership = """<html> <body> <p><span style="font-weight:600;">{status_label}</span> : <span style="color:{status_color};">{status}</span> - <span>{status_info}</span></p> </body> </html>""".format(status_color=status_color, status_label=self.tr("Status"), status=status_value, status_info=status_info) description_identity = """<html> <body> <p><span style="font-weight:600;">{nb_certs_label}</span> : {nb_certs} ({outdistanced_text})</p> <p><span style="font-weight:600;">{mstime_remaining_label}</span> : {mstime_remaining}</p> </body> </html>""".format(nb_certs_label=self.tr("Certs. received"), nb_certs=data['nb_certs'], outdistanced_text=data['outdistanced'], mstime_remaining_label=self.tr("Membership"), mstime_remaining=mstime_remaining_text) self.label_currency.setText(description_currency) if data['is_identity']: self.label_membership.setText(description_membership) self.label_identity.setText(description_identity) self.button_membership.setText(membership_action_value) self.button_membership.setEnabled(membership_action_enabled) else: self.label_membership.hide() self.label_identity.hide() self.button_membership.hide()
def set_simple_informations(self, data, state): if state in (IdentityView.CommunityState.NOT_INIT, IdentityView.CommunityState.OFFLINE): self.label_currency.setText("""<html> <body> <p> <span style=" font-size:16pt; font-weight:600;">{currency}</span> </p> <p>{message}</p> </body> </html>""".format(currency=data['currency'], message=IdentityView.simple_message[state])) self.button_membership.hide() else: if data['written']: written_value = self.tr("Identity written in blockchain") else: expiration_text = QLocale.toString( QLocale(), QDateTime.fromTime_t(data['idty_expiration']), QLocale.dateTimeFormat(QLocale(), QLocale.ShortFormat)) written_value = self.tr("Identity not written in blockchain") + \ " (" + self.tr("Expires on : {0}").format(expiration_text) + " BAT)" status_value = self.tr( "Member") if data['membership_state'] else self.tr( "Non-Member") if data['mstime'] > 0: membership_action_value = self.tr("Renew membership") status_info = "" membership_action_enabled = True elif data['membership_state']: membership_action_value = self.tr("Renew membership") status_info = "Your membership expired" membership_action_enabled = True else: membership_action_value = self.tr("Request membership") if data['nb_certs'] > data['nb_certs_required']: status_info = self.tr("Registration ready") membership_action_enabled = True else: status_info = self.tr("{0} more certifications required")\ .format(data['nb_certs_required'] - data['nb_certs']) membership_action_enabled = True if data['mstime'] > 0: days, hours, minutes, seconds = timestamp_to_dhms( data['mstime']) mstime_remaining_text = self.tr("Expires in ") if days > 0: mstime_remaining_text += "{days} days".format(days=days) else: mstime_remaining_text += "{hours} hours and {min} min.".format( hours=hours, min=minutes) else: mstime_remaining_text = self.tr("Expired or never published") ms_status_color = '#00AA00' if data[ 'membership_state'] else '#FF0000' outdistanced_status_color = '#FF0000' if data[ 'is_outdistanced'] else '#00AA00' if data['written']: written_status_color = "#00AA00" elif data['idty_expired']: written_status_color = "#FF0000" else: written_status_color = '#FF6347' description_membership = """<html> <body> <p><span style="font-weight:600;">{status_label}</span> : <span style="color:{ms_status_color};">{status}</span> - <span>{status_info}</span></p> </body> </html>""".format(ms_status_color=ms_status_color, status_label=self.tr("Status"), status=status_value, status_info=status_info) description_identity = """<html> <body> <p><span style="font-weight:600;">{nb_certs_label}</span> : {nb_certs} <span style="color:{outdistanced_status_color};">({outdistanced_text})</span></p> <p><span style="font-weight:600;">{mstime_remaining_label}</span> : {mstime_remaining}</p> </body> </html>""".format(nb_certs_label=self.tr("Certs. received"), nb_certs=data['nb_certs'], outdistanced_text=data['outdistanced'], outdistanced_status_color=outdistanced_status_color, mstime_remaining_label=self.tr("Membership"), mstime_remaining=mstime_remaining_text) self.label_written.setText(""" <html> <body> <p><span style="font-weight:450; color:{written_status_color};">{written_label}</span></p> </body> </html> """.format(written_label=written_value, written_status_color=written_status_color)) if data['is_identity']: self.label_membership.setText(description_membership) self.label_identity.setText(description_identity) self.button_membership.setText(membership_action_value) self.button_membership.setEnabled(membership_action_enabled) else: self.label_membership.hide() self.label_identity.hide() self.button_membership.hide()