From e7f48f3ce03ede0f8cdfeff350bec50849bbad44 Mon Sep 17 00:00:00 2001 From: PhilipWafula Date: Wed, 12 May 2021 12:51:55 +0300 Subject: [PATCH] Refactors to fix hard-coded token symbols. --- apps/cic-ussd/cic_ussd/conversions.py | 8 ++++---- .../cic-ussd/cic_ussd/state_machine/logic/transaction.py | 9 +++++++-- apps/cic-ussd/cic_ussd/transactions.py | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/apps/cic-ussd/cic_ussd/conversions.py b/apps/cic-ussd/cic_ussd/conversions.py index 192c4aa4..d2de2546 100644 --- a/apps/cic-ussd/cic_ussd/conversions.py +++ b/apps/cic-ussd/cic_ussd/conversions.py @@ -24,7 +24,7 @@ def from_wei(value: int) -> float: """This function converts values in Wei to a token in the cic network. :param value: Value in Wei :type value: int - :return: SRF equivalent of value in Wei + :return: platform's default token equivalent of value in Wei :rtype: float """ value = float(value) / 1e+6 @@ -33,9 +33,9 @@ def from_wei(value: int) -> float: def to_wei(value: int) -> int: """This functions converts values from a token in the cic network to Wei. - :param value: Value in SRF + :param value: Value in platform's default token :type value: int - :return: Wei equivalent of value in SRF + :return: Wei equivalent of value in platform's default token :rtype: int """ - return int(value * 1e+6) \ No newline at end of file + return int(value * 1e+6) diff --git a/apps/cic-ussd/cic_ussd/state_machine/logic/transaction.py b/apps/cic-ussd/cic_ussd/state_machine/logic/transaction.py index eee2c7df..2c4bbf02 100644 --- a/apps/cic-ussd/cic_ussd/state_machine/logic/transaction.py +++ b/apps/cic-ussd/cic_ussd/state_machine/logic/transaction.py @@ -12,6 +12,7 @@ from cic_ussd.chain import Chain from cic_ussd.db.models.account import AccountStatus, Account from cic_ussd.operations import save_to_in_memory_ussd_session_data from cic_ussd.phone_number import get_user_by_phone_number +from cic_ussd.processor import retrieve_token_symbol from cic_ussd.redis import create_cached_data_key, get_cached_data from cic_ussd.transactions import OutgoingTransactionProcessor @@ -124,14 +125,18 @@ def process_transaction_request(state_machine_data: Tuple[str, dict, Account]): """ user_input, ussd_session, user = state_machine_data + # retrieve token symbol + chain_str = Chain.spec.__str__() + # get user from phone number recipient_phone_number = ussd_session.get('session_data').get('recipient_phone_number') recipient = get_user_by_phone_number(phone_number=recipient_phone_number) to_address = recipient.blockchain_address from_address = user.blockchain_address amount = int(ussd_session.get('session_data').get('transaction_amount')) - chain_str = Chain.spec.__str__() + token_symbol = retrieve_token_symbol(chain_str=chain_str) + outgoing_tx_processor = OutgoingTransactionProcessor(chain_str=chain_str, from_address=from_address, to_address=to_address) - outgoing_tx_processor.process_outgoing_transfer_transaction(amount=amount) + outgoing_tx_processor.process_outgoing_transfer_transaction(amount=amount, token_symbol=token_symbol) diff --git a/apps/cic-ussd/cic_ussd/transactions.py b/apps/cic-ussd/cic_ussd/transactions.py index be08d745..ab235b72 100644 --- a/apps/cic-ussd/cic_ussd/transactions.py +++ b/apps/cic-ussd/cic_ussd/transactions.py @@ -120,7 +120,7 @@ class OutgoingTransactionProcessor: self.from_address = from_address self.to_address = to_address - def process_outgoing_transfer_transaction(self, amount: int, token_symbol='SRF'): + def process_outgoing_transfer_transaction(self, amount: int, token_symbol: str): """This function initiates standard transfers between one account to another :param amount: The amount of tokens to be sent :type amount: int