예제 #1
0
    def fetch_exchange_rate(user: User):
        from_token = default_token(user)

        default_limit, limit_amount = TokenProcessor.get_default_limit(
            user, from_token)
        exchange_rate_full_precision = TokenProcessor.get_exchange_rate(
            user, from_token)

        exchange_limit = rounded_dollars(limit_amount)
        exchange_rate = round_to_sig_figs(exchange_rate_full_precision, 3)
        exchange_sample_value = round(exchange_rate_full_precision *
                                      float(1000))

        if exchange_limit:
            TokenProcessor.send_sms(
                user,
                "exchange_rate_can_exchange_sms",
                token_name=from_token.symbol,
                exchange_rate=exchange_rate,
                exchange_limit=exchange_limit,
                exchange_sample_value=exchange_sample_value,
                limit_period=default_limit.time_period_days)
        else:
            TokenProcessor.send_sms(
                user,
                "exchange_rate_sms",
                token_name=from_token.symbol,
                exchange_rate=exchange_rate,
                exchange_sample_value=exchange_sample_value,
            )
예제 #2
0
 def standard_string(t):
     if t['limit'].total_amount:
         allowed_amount = f"{rounded_dollars(str(t['limit'].total_amount))}"
         rounded_rate = round_to_sig_figs(t['exchange_rate'], 3)
         return (
             f"{allowed_amount} {t['name']} (1 {t['name']} = {rounded_rate} {reserve_token.symbol})"
         )
     else:
         return ""
예제 #3
0
 def ge_string(t):
     if t['limit'].transfer_balance_fraction:
         # TODO: This doesn't seem DRY with respect to 'get default exchange rate'
         allowed_amount = rounded_dollars(
             t['limit'].transfer_balance_fraction * t['balance'])
         rounded_rate = round_to_sig_figs(t['exchange_rate'], 3)
         return (
             f"{allowed_amount} {t['name']} (1 {t['name']} = {rounded_rate} {reserve_token.symbol})"
         )
     else:
         return ""
예제 #4
0
        def token_string(limit_type: Type[AggregateLimit], t: dict):
            if isinstance(t['limit'], limit_type):

                with ephemeral_alchemy_object(
                        CreditTransfer,
                        transfer_type=TransferTypeEnum.PAYMENT,
                        transfer_subtype=TransferSubTypeEnum.AGENT_OUT,
                        sender_user=user,
                        recipient_user=user,
                        token=t['token'],
                        amount=0) as dummy_transfer:

                    allowed_amount = f"{rounded_dollars(str(t['limit'].available_base(dummy_transfer)))}"
                    rounded_rate = round_to_sig_figs(t['exchange_rate'], 3)
                    return (
                        f"{allowed_amount} {t['name']} (1 {t['name']} = {rounded_rate} {reserve_token.symbol})"
                    )
            else:
                return ""