Ejemplo n.º 1
0
        protected override async Task ProcessMessageAsync(TransferToInternalDetectedEvent message)
        {
            await _handler.HandleAsync(message.OperationId, message.PrivateAddress, message.PublicAddress,
                                       Money18.Parse(message.Amount.ToString()), message.PublicTransferId);

            _log.Info("Processed TransferToInternalDetectedEvent", message);
        }
Ejemplo n.º 2
0
 public void Ceiling__Produces_Correct_result(string a, string b)
 {
     Money18
     .Ceiling(Money18.Parse(a))
     .Should()
     .Be(b);
 }
Ejemplo n.º 3
0
        public async Task <OperationFeesModel> GetOperationFeesAsync()
        {
            var operationFees = new OperationFeesModel();

            var operationFeesConfig = await _crossChainWalletLinkerClient.ConfigurationApi.GetAllAsync();

            foreach (var model in operationFeesConfig)
            {
                switch (model.Type)
                {
                case ConfigurationItemType.FirstTimeLinkingFee:
                    operationFees.FirstTimeLinkingFee = Money18.Parse(model.Value);
                    break;

                case ConfigurationItemType.SubsequentLinkingFee:
                    operationFees.SubsequentLinkingFee = Money18.Parse(model.Value);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            var crossChainTransferFee = await _crossChainTransfersClient.FeesApi.GetTransferToPublicFeeAsync();

            operationFees.CrossChainTransferFee = crossChainTransferFee.Fee;

            return(operationFees);
        }
Ejemplo n.º 4
0
 public void Abs__Produces_Correct_Result(string a, string b)
 {
     Money18
     .Abs(Money18.Parse(a))
     .Should()
     .Be(b);
 }
        private async Task <Money18> CalculateConditionRewardByPercentageAsync(Money18 percentage,
                                                                               ConditionCompletion conditionCompletion, string paymentId = null)
        {
            Money18 rewardsAmount = 0;

            foreach (var completionData in conditionCompletion.Data)
            {
                if (paymentId != null && completionData.ContainsKey(paymentId))
                {
                    var rewardDictionary = completionData[paymentId];

                    var paymentDictionary = JsonConvert.DeserializeObject <Dictionary <string, string> >(rewardDictionary);

                    rewardsAmount += Money18.Parse(paymentDictionary[AmountName]);
                }
                else if (paymentId == null && completionData != null && completionData.ContainsKey(AmountName))
                {
                    rewardsAmount += Money18.Parse(completionData[AmountName]);
                }
            }

            var amountInCurrency = rewardsAmount * (percentage / 100m);

            return(await GetEligibilityEngineAmountByCondition(conditionCompletion, amountInCurrency));
        }
Ejemplo n.º 6
0
 public void Truncate__Produces_Correct_Result(string a, string b)
 {
     Money18
     .Truncate(Money18.Parse(a))
     .Should()
     .Be(b);
 }
Ejemplo n.º 7
0
 public void Round__Scale_Specified__Produces_Correct_Result(string a, string b)
 {
     Money18
     .Round(Money18.Parse(a), 2)
     .Should()
     .Be(b);
 }
Ejemplo n.º 8
0
 public void Parse__Value_Correctly_Parsed(string a)
 {
     Money18
     .Parse(a)
     .Should()
     .Be(a);
 }
Ejemplo n.º 9
0
 public override object ConvertFrom(
     ITypeDescriptorContext context,
     CultureInfo culture,
     object value)
 {
     return(Money18.Parse((string)value));
 }
 public void Cast_To_Decimal__Produces_Correct_Result(
     string value,
     string expectedResult)
 {
     ((decimal)Money18.Parse(value))
     .Should()
     .Be(decimal.Parse(expectedResult));
 }
        private async Task <Money18?> GetCachedValue(string walletAddress)
        {
            var value = await _distributedCache.GetStringAsync(GetCacheKey(walletAddress));

            return(string.IsNullOrEmpty(value)
                ? new Money18?()
                : Money18.Parse(value));
        }
Ejemplo n.º 12
0
        public void Parse__Invalid_String_Passed__FormatException_Thrown(string a)
        {
            // ReSharper disable once ReturnValueOfPureMethodIsNotUsed
            Action parse = () => Money18.Parse(a);

            parse
            .Should()
            .ThrowExactly <FormatException>();
        }
Ejemplo n.º 13
0
        public void Decimal_Places()
        {
            var nfi = CultureInfo.InvariantCulture.NumberFormat;
            var str = "123.1239";

            Assert.AreEqual(Money18.Parse(str).ToString("R", 1, nfi), "123.1");
            Assert.AreEqual(Money18.Parse(str).ToString("R", 2, nfi), "123.12");
            Assert.AreEqual(Money18.Parse(str).ToString("R", 3, nfi), "123.123");
            Assert.AreEqual(Money18.Parse("123.1").ToString("R", 2, nfi), "123.10");
        }
Ejemplo n.º 14
0
        public void Number_Formats()
        {
            var nfi = new NumberFormatInfo();

            nfi.NumberDecimalSeparator = ".";
            Assert.AreEqual(Money18.Parse("0.1").ToString("R", nfi), "0.1");

            nfi.NumberDecimalSeparator = ",";
            Assert.AreEqual(Money18.Parse("0.1").ToString("R", nfi), "0,1");
        }
Ejemplo n.º 15
0
        public void Integer_Part_Formats()
        {
            Assert.AreEqual(Money18.Parse("123456789").ToString("D6"), "123456789");
            Assert.AreEqual(Money18.Parse("123456789").ToString("d10"), "0123456789");

            Assert.AreEqual(Money18.Parse("123456789").ToString("G6"), "123456789");
            Assert.AreEqual(Money18.Parse("123456789").ToString("g10"), "0123456789");

            Assert.AreEqual(Money18.Parse("123456789").ToString("R6"), "123456789");
            Assert.AreEqual(Money18.Parse("123456789").ToString("r10"), "0123456789");
        }
        private async Task <Money18> CalculateConditionRewardByConversionRate(ConditionCompletion conditionCompletion)
        {
            Money18 rewardsAmount = 0;

            foreach (var completionData in conditionCompletion.Data)
            {
                if (completionData != null && completionData.ContainsKey(AmountName))
                {
                    rewardsAmount += Money18.Parse(completionData[AmountName]);
                }
            }

            return(await GetEligibilityEngineAmountByCondition(conditionCompletion, rewardsAmount));
        }
        private async Task SetRewardRatioGivenBonusAmountAsync(ConditionLocalizedResponse condition, string customerId, Dictionary <string, string> dictionary, RatioCompletion ratioCompletion)
        {
            var     amount      = dictionary["Amount"];
            Money18 givenReward = 0m;
            Money18 totalReward = 0m;

            //calculate bonus
            switch (condition.RewardType)
            {
            case RewardType.Fixed:
            {
                givenReward = CalculateReward(condition.RewardRatio.Ratios, condition.ImmediateReward, ratioCompletion.GivenThreshold);
                totalReward = condition.ImmediateReward;
            }
            break;

            case RewardType.Percentage:
                if (amount != null)
                {
                    var amountInCurrency = Money18.Parse(amount) * (condition.ImmediateReward / 100m);

                    var convertedAmount = await GetEligibilityEngineAmountByCondition(Guid.Parse(condition.Id),
                                                                                      Guid.Parse(customerId), amountInCurrency);

                    givenReward = CalculateReward(condition.RewardRatio.Ratios, convertedAmount, ratioCompletion.GivenThreshold);
                    totalReward = convertedAmount;
                }

                break;

            case RewardType.ConversionRate:
            {
                var convertedAmount = await GetEligibilityEngineAmountByCondition(Guid.Parse(condition.Id),
                                                                                  Guid.Parse(customerId), condition.ImmediateReward);

                givenReward = CalculateReward(condition.RewardRatio.Ratios, convertedAmount, ratioCompletion.GivenThreshold);
                totalReward = convertedAmount;
            }
            break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            ratioCompletion.GivenRatioRewardBonus = givenReward.ToDisplayString();
            ratioCompletion.TotalRatioRewardBonus = totalReward.ToDisplayString();
        }
        private async Task <Money18> CalculateRewardByConversionRate(
            string campaignId,
            string customerId,
            IEnumerable <ConditionCompletion> conditionCompletions)
        {
            Money18 rewardsAmount = 0;

            foreach (var completion in conditionCompletions)
            {
                foreach (var completionData in completion.Data)
                {
                    if (completionData != null && completionData.ContainsKey(AmountName))
                    {
                        rewardsAmount += Money18.Parse(completionData[AmountName]);
                    }
                }
            }

            return(await GetEligibilityEngineAmountByEarnRuleAsync(campaignId, customerId, rewardsAmount));
        }
        private async Task <Money18> CalculateEarnRuleRewardByPercentageAsync(string campaignId, string customerId, Money18 percentage,
                                                                              IEnumerable <ConditionCompletion> conditionCompletions)
        {
            Money18 rewardsAmount = 0;

            foreach (var completion in conditionCompletions)
            {
                foreach (var completionData in completion.Data)
                {
                    if (completionData != null && completionData.ContainsKey(AmountName))
                    {
                        rewardsAmount += Money18.Parse(completionData[AmountName]);
                    }
                }
            }

            var amountInCurrency = rewardsAmount * (percentage / 100m);

            return(await GetEligibilityEngineAmountByEarnRuleAsync(campaignId, customerId, amountInCurrency));
        }
 public void Conversion_To_Decimal_From_String__Produces_Correct_Result()
 {
     (decimal.Parse(Money18.Parse("782142909635475295147619.59932").ToString()))
     .Should()
     .Be(782142909635475295147619.59932m);
 }
Ejemplo n.º 21
0
 private static (Money18 Left, Money18 Right) Parse(string left, string right)
 {
     return(Money18.Parse(left), Money18.Parse(right));
 }
Ejemplo n.º 22
0
        public async Task <ConversionRateResponseModel> GetPartnerRateAsync(
            [FromQuery] PartnerConversionRateRequestModel request)
        {
            if (!Guid.TryParse(request.PartnerId, out var partnerIdIdAsGuid))
            {
                return new ConversionRateResponseModel {
                           Error = ConversionRateErrorCodes.InvalidPartnerId
                }
            }
            ;

            if (!Guid.TryParse(_requestContext.UserId, out var customerIdAsGuid))
            {
                return new ConversionRateResponseModel {
                           Error = ConversionRateErrorCodes.InvalidCustomerId
                }
            }
            ;

            var result = await _eligibilityEngineClient.ConversionRate.ConvertOptimalByPartnerAsync(
                new ConvertOptimalByPartnerRequest
            {
                CustomerId   = customerIdAsGuid,
                FromCurrency = _settingsService.GetEmaarTokenName(),
                ToCurrency   = _settingsService.GetBaseCurrencyCode(),
                Amount       = Money18.Parse(request.Amount),
                PartnerId    = partnerIdIdAsGuid
            });

            switch (result.ErrorCode)
            {
            case EligibilityEngineErrors.PartnerNotFound:
                return(new ConversionRateResponseModel
                {
                    Error = ConversionRateErrorCodes.PartnerNotFound
                });

            case EligibilityEngineErrors.CustomerNotFound:
                return(new ConversionRateResponseModel
                {
                    Error = ConversionRateErrorCodes.CustomerNotFound
                });

            case EligibilityEngineErrors.EarnRuleNotFound:
                return(new ConversionRateResponseModel
                {
                    Error = ConversionRateErrorCodes.EarnRuleNotFound
                });

            case EligibilityEngineErrors.ConversionRateNotFound:
                return(new ConversionRateResponseModel
                {
                    Error = ConversionRateErrorCodes.ConversionRateNotFound
                });

            default:
                return(new ConversionRateResponseModel
                {
                    Rate = result.UsedRate.ToDisplayString(),
                    Amount = result.Amount.ToDisplayString(),
                    CurrencyCode = result.CurrencyCode
                });
            }
        }
Ejemplo n.º 23
0
 public void Trailing_Zeros_Are_Trimmed()
 {
     Assert.AreEqual(Money18.Parse("0.0100").ToString(), "0.01");
 }
Ejemplo n.º 24
0
        public void Custom_Formats()
        {
            var nfi = CultureInfo.InvariantCulture.NumberFormat;

            Assert.AreEqual(Money18.Parse("123456789.123").ToString("N0", 2, nfi), (123456789.12).ToString("N2"));
        }
Ejemplo n.º 25
0
 public void No_Decimal_Places_Added()
 {
     Assert.AreEqual(Money18.Parse("30").ToString(), "30");
 }
Ejemplo n.º 26
0
 private static Money18?ToNullableMoney18(string str)
 {
     return(string.IsNullOrWhiteSpace(str) ? default(Money18?) : Money18.Parse(str));
 }
        protected override async Task ProcessMessageAsync(TransferToExternalFailedEvent message)
        {
            await _handler.HandleAsync(message.CustomerId, Money18.Parse(message.Amount.ToString()));

            _log.Info("Processed TransferToExternalFailedEvent", message);
        }
Ejemplo n.º 28
0
        protected override async Task ProcessMessageAsync(TransferToExternalCompletedEvent message)
        {
            await _handler.HandleAsync(message.PrivateAddress, Money18.Parse(message.Amount.ToString()), message.EventId);

            _log.Info("Processed TransferToExternalCompletedEvent", message);
        }
Ejemplo n.º 29
0
 public void No_Trailing_Zeros()
 {
     Assert.IsFalse(Money18.Parse("0.01").ToString().EndsWith('0'));
 }
 public void Parsing_From_Decimal__Produces_Correct_Result()
 {
     ((decimal)Money18.Parse(782142909635475295147619.59932m.ToString()))
     .Should()
     .Be(782142909635475295147619.59932m);
 }