Refactors to fix hard-coded token symbols.

This commit is contained in:
PhilipWafula 2021-05-12 12:51:55 +03:00
parent b252fab018
commit e7f48f3ce0
Signed by untrusted user: mango-habanero
GPG Key ID: B00CE9034DA19FB7
3 changed files with 12 additions and 7 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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