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); }
public void Ceiling__Produces_Correct_result(string a, string b) { Money18 .Ceiling(Money18.Parse(a)) .Should() .Be(b); }
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); }
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)); }
public void Truncate__Produces_Correct_Result(string a, string b) { Money18 .Truncate(Money18.Parse(a)) .Should() .Be(b); }
public void Round__Scale_Specified__Produces_Correct_Result(string a, string b) { Money18 .Round(Money18.Parse(a), 2) .Should() .Be(b); }
public void Parse__Value_Correctly_Parsed(string a) { Money18 .Parse(a) .Should() .Be(a); }
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)); }
public void Parse__Invalid_String_Passed__FormatException_Thrown(string a) { // ReSharper disable once ReturnValueOfPureMethodIsNotUsed Action parse = () => Money18.Parse(a); parse .Should() .ThrowExactly <FormatException>(); }
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"); }
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"); }
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); }
private static (Money18 Left, Money18 Right) Parse(string left, string right) { return(Money18.Parse(left), Money18.Parse(right)); }
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 }); } }
public void Trailing_Zeros_Are_Trimmed() { Assert.AreEqual(Money18.Parse("0.0100").ToString(), "0.01"); }
public void Custom_Formats() { var nfi = CultureInfo.InvariantCulture.NumberFormat; Assert.AreEqual(Money18.Parse("123456789.123").ToString("N0", 2, nfi), (123456789.12).ToString("N2")); }
public void No_Decimal_Places_Added() { Assert.AreEqual(Money18.Parse("30").ToString(), "30"); }
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); }
protected override async Task ProcessMessageAsync(TransferToExternalCompletedEvent message) { await _handler.HandleAsync(message.PrivateAddress, Money18.Parse(message.Amount.ToString()), message.EventId); _log.Info("Processed TransferToExternalCompletedEvent", message); }
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); }