Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjusted the currency options for Path of Exile 2 #353

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/Sidekick.Apis.Poe/Bulk/BulkTradeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
using Sidekick.Apis.Poe.Bulk.Models;
using Sidekick.Apis.Poe.Bulk.Results;
using Sidekick.Apis.Poe.Clients;
using Sidekick.Apis.Poe.Trade.Models;
using Sidekick.Apis.Poe.Filters;
using Sidekick.Apis.Poe.Trade.Requests;
using Sidekick.Apis.Poe.Trade.Results;
using Sidekick.Common.Enums;
using Sidekick.Common.Exceptions;
using Sidekick.Common.Extensions;
using Sidekick.Common.Game;
Expand All @@ -22,6 +21,7 @@ public class BulkTradeService(
IGameLanguageProvider gameLanguageProvider,
ISettingsService settingsService,
IPoeTradeClient poeTradeClient,
IFilterProvider filterProvider,
IItemStaticDataProvider itemStaticDataProvider) : IBulkTradeService
{
private readonly ILogger logger = logger;
Expand All @@ -31,7 +31,7 @@ public bool SupportsBulkTrade(Item? item)
return item?.Metadata.Rarity == Rarity.Currency && itemStaticDataProvider.GetId(item.Metadata) != null;
}

public async Task<BulkResponseModel> SearchBulk(Item item, TradeCurrency currency, int minStock)
public async Task<BulkResponseModel> SearchBulk(Item item)
{
logger.LogInformation("[Trade API] Querying Exchange API.");

Expand All @@ -44,25 +44,28 @@ public async Task<BulkResponseModel> SearchBulk(Item item, TradeCurrency currenc
throw new ApiErrorException("[Trade API] Could not find a valid item.");
}

var currency = item.Metadata.Game == GameType.PathOfExile ? await settingsService.GetString(SettingKeys.PriceCheckBulkCurrency) : await settingsService.GetString(SettingKeys.PriceCheckBulkCurrencyPoE2);
currency = filterProvider.GetPriceOption(currency);
var minStock = await settingsService.GetInt(SettingKeys.PriceCheckBulkMinimumStock);

var model = new BulkQueryRequest();
model.Query.Want.Add(itemId);
model.Query.Minimum = minStock;

if (currency == TradeCurrency.ChaosEquivalent || currency == TradeCurrency.ChaosOrDivine)
if (currency == null || currency == "chaos_divine")
{
if (model.Query.Want.Any(x => x == TradeCurrency.Chaos.GetValueAttribute()))
if (item.Metadata.Game == GameType.PathOfExile)
{
model.Query.Have.Add(TradeCurrency.Divine.GetValueAttribute()!);
model.Query.Have.Add(model.Query.Want.Any(x => x == "chaos") ? "divine" : "chaos");
}
else
{
model.Query.Have.Add(TradeCurrency.Chaos.GetValueAttribute()!);
model.Query.Have.Add(model.Query.Want.Any(x => x == "exalted") ? "divine" : "exalted");
}
}
else
{
var have = currency.GetValueAttribute();
model.Query.Have.Add(have!);
model.Query.Have.Add(currency);
}

var json = JsonSerializer.Serialize(model, poeTradeClient.Options);
Expand Down
3 changes: 1 addition & 2 deletions src/Sidekick.Apis.Poe/Bulk/IBulkTradeService.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using Sidekick.Apis.Poe.Bulk.Models;
using Sidekick.Apis.Poe.Trade.Models;
using Sidekick.Common.Game.Items;

namespace Sidekick.Apis.Poe.Bulk
{
public interface IBulkTradeService
{
Task<BulkResponseModel> SearchBulk(Item item, TradeCurrency currency, int minStock);
Task<BulkResponseModel> SearchBulk(Item item);

bool SupportsBulkTrade(Item? item);

Expand Down
12 changes: 11 additions & 1 deletion src/Sidekick.Apis.Poe/Filters/FilterProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ public class FilterProvider
ICacheProvider cacheProvider
) : IFilterProvider
{
public List<ApiFilterOption> ApiItemCategories { get; set; } = new();
public List<ApiFilterOption> ApiItemCategories { get; private set; } = new();

public List<ApiFilterOption> PriceOptions { get; private set; } = new();

/// <inheritdoc/>
public int Priority => 100;
Expand All @@ -32,6 +34,14 @@ public async Task Initialize()

ApiItemCategories = result.Result.First(x => x.Id == "type_filters").Filters
.First(x => x.Id == "category").Option!.Options;

PriceOptions = result.Result.First(x => x.Id == "trade_filters").Filters
.First(x => x.Id == "price").Option!.Options;
}

public string? GetPriceOption(string? price)
{
var option = PriceOptions.SingleOrDefault(x => x.Id == price);
return option?.Id;
}
}
6 changes: 5 additions & 1 deletion src/Sidekick.Apis.Poe/Filters/IFilterProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ namespace Sidekick.Apis.Poe.Filters;

public interface IFilterProvider : IInitializableService
{
List<ApiFilterOption> ApiItemCategories { get; set; }
List<ApiFilterOption> ApiItemCategories { get; }

List<ApiFilterOption> PriceOptions { get; }

string? GetPriceOption(string? price);
}
2 changes: 1 addition & 1 deletion src/Sidekick.Apis.Poe/ITradeSearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Sidekick.Apis.Poe
{
public interface ITradeSearchService
{
Task<TradeSearchResult<string>> Search(Item item, TradeCurrency currency, PropertyFilters? propertyFilters = null, List<ModifierFilter>? modifierFilters = null, List<PseudoModifierFilter>? pseudoFilters = null);
Task<TradeSearchResult<string>> Search(Item item, PropertyFilters? propertyFilters = null, List<ModifierFilter>? modifierFilters = null, List<PseudoModifierFilter>? pseudoFilters = null);

Task<List<TradeItem>> GetResults(GameType game, string queryId, List<string> ids, List<PseudoModifierFilter>? pseudoFilters = null);

Expand Down
64 changes: 0 additions & 64 deletions src/Sidekick.Apis.Poe/Trade/Models/TradeCurrency.cs

This file was deleted.

14 changes: 8 additions & 6 deletions src/Sidekick.Apis.Poe/Trade/TradeSearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
using Microsoft.Extensions.Logging;
using Sidekick.Apis.Poe.Clients;
using Sidekick.Apis.Poe.Clients.Models;
using Sidekick.Apis.Poe.Filters;
using Sidekick.Apis.Poe.Modifiers;
using Sidekick.Apis.Poe.Trade.Models;
using Sidekick.Apis.Poe.Trade.Requests;
using Sidekick.Apis.Poe.Trade.Requests.Filters;
using Sidekick.Apis.Poe.Trade.Requests.Models;
using Sidekick.Apis.Poe.Trade.Results;
using Sidekick.Common.Enums;
using Sidekick.Common.Exceptions;
using Sidekick.Common.Extensions;
using Sidekick.Common.Game;
Expand All @@ -26,12 +26,13 @@ public class TradeSearchService
IGameLanguageProvider gameLanguageProvider,
ISettingsService settingsService,
IPoeTradeClient poeTradeClient,
IModifierProvider modifierProvider
IModifierProvider modifierProvider,
IFilterProvider filterProvider
) : ITradeSearchService
{
private readonly ILogger logger = logger;

public async Task<TradeSearchResult<string>> Search(Item item, TradeCurrency currency, PropertyFilters? propertyFilters = null, List<ModifierFilter>? modifierFilters = null, List<PseudoModifierFilter>? pseudoFilters = null)
public async Task<TradeSearchResult<string>> Search(Item item, PropertyFilters? propertyFilters = null, List<ModifierFilter>? modifierFilters = null, List<PseudoModifierFilter>? pseudoFilters = null)
{
try
{
Expand Down Expand Up @@ -91,14 +92,15 @@ public async Task<TradeSearchResult<string>> Search(Item item, TradeCurrency cur
query.Filters.TypeFilters.Filters.Rarity = new SearchFilterOption("nonunique");
}

var currencyValue = currency.GetValueAttribute();
if (!string.IsNullOrEmpty(currencyValue))
var currency = item.Metadata.Game == GameType.PathOfExile ? await settingsService.GetString(SettingKeys.PriceCheckItemCurrency) : await settingsService.GetString(SettingKeys.PriceCheckItemCurrencyPoE2);
currency = filterProvider.GetPriceOption(currency);
if (!string.IsNullOrEmpty(currency))
{
query.Filters.TradeFilters = new TradeFilterGroup
{
Filters =
{
Price = new SearchFilterValue(currencyValue),
Price = new SearchFilterValue(currency),
},
};
}
Expand Down
13 changes: 0 additions & 13 deletions src/Sidekick.Common.Blazor/Settings/General/LeagueIdEditor.razor
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,6 @@
LeagueId = value;
await SettingsService.Set(SettingKeys.LeagueId, value);

if (currentGame != newGame)
{
if (newGame == GameType.PathOfExile2)
{
await SettingsService.Set(SettingKeys.PriceCheckBulkCurrency, TradeCurrency.Exalted);
await SettingsService.Set(SettingKeys.PriceCheckItemCurrency, TradeCurrency.ChaosEquivalent);
}
else if (newGame == GameType.PathOfExile)
{
await SettingsService.Set(SettingKeys.PriceCheckBulkCurrency, TradeCurrency.Divine);
}
}

if (AutoRefresh && currentGame != newGame)
{
await CacheProvider.Clear();
Expand Down
16 changes: 12 additions & 4 deletions src/Sidekick.Common.Ui/Forms/FormSelect.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<select id="@Id"
@onchange="OnChange"
class="@UiClasses.FormInputClasses p-2 text-base w-full mb-3">
@if (Options.All(x => x.Value != Value))
@if (Options.All(x => GetOptionValue(x.Value) != GetOptionValue(Value)))
{
<option selected></option>
}
Expand All @@ -21,7 +21,7 @@
<optgroup label="@group.Key">
@foreach (var option in group)
{
<option selected="@(option.Value == Value)" value="@option.Value" disabled="@option.Disabled">@option.Label</option>
<option selected="@(GetOptionValue(option.Value) == GetOptionValue(Value))" value="@GetOptionValue(option.Value)" disabled="@option.Disabled">@option.Label</option>
}
</optgroup>
}
Expand All @@ -30,7 +30,7 @@
{
foreach (var option in Options)
{
<option selected="@(option.Value == Value)" value="@option.Value" disabled="@option.Disabled">@option.Label</option>
<option selected="@(GetOptionValue(option.Value) == GetOptionValue(Value))" value="@GetOptionValue(option.Value)" disabled="@option.Disabled">@option.Label</option>
}
}
</select>
Expand All @@ -51,8 +51,16 @@

private string Id { get; } = UiUtilities.GenerateId();

private string GetOptionValue(string? value) => value ?? "null";

private async Task OnChange(ChangeEventArgs args)
{
await ValueChanged.InvokeAsync(args.Value?.ToString());
var newValue = args.Value?.ToString();
if (newValue == "null")
{
newValue = null;
}

await ValueChanged.InvokeAsync(newValue);
}
}
2 changes: 2 additions & 0 deletions src/Sidekick.Common/Settings/SettingKeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ public static class SettingKeys
public const string PriceCheckCloseWithMouse = nameof(PriceCheckCloseWithMouse);
public const string PriceCheckPredictionEnabled = nameof(PriceCheckPredictionEnabled);
public const string PriceCheckItemCurrency = nameof(PriceCheckItemCurrency);
public const string PriceCheckItemCurrencyPoE2 = nameof(PriceCheckItemCurrencyPoE2);
public const string PriceCheckBulkCurrency = nameof(PriceCheckBulkCurrency);
public const string PriceCheckBulkCurrencyPoE2 = nameof(PriceCheckBulkCurrencyPoE2);
public const string PriceCheckBulkMinimumStock = nameof(PriceCheckBulkMinimumStock);
public const string PriceCheckCurrencyMode = nameof(PriceCheckCurrencyMode);
public const string PriceCheckNormalizeValue = nameof(PriceCheckNormalizeValue);
Expand Down
6 changes: 1 addition & 5 deletions src/Sidekick.Modules.Trade/PriceCheckService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,8 @@ public async Task ItemSearch()
IsLoading = true;
LoadingChanged?.Invoke();

var tradeCurrency = await settingsService.GetEnum<TradeCurrency>(SettingKeys.PriceCheckItemCurrency) ?? TradeCurrency.Chaos;
ItemTradeResult = await tradeSearchService.Search(
Item,
tradeCurrency,
PropertyFilters,
ModifierFilters,
PseudoFilters);
Expand Down Expand Up @@ -151,9 +149,7 @@ public async Task BulkSearch()
IsLoading = true;
LoadingChanged?.Invoke();

var currency = await settingsService.GetEnum<TradeCurrency>(SettingKeys.PriceCheckBulkCurrency);
var minStock = await settingsService.GetInt(SettingKeys.PriceCheckBulkMinimumStock);
BulkTradeResult = await bulkTradeService.SearchBulk(Item, currency ?? TradeCurrency.Divine, minStock);
BulkTradeResult = await bulkTradeService.SearchBulk(Item);

IsLoading = false;
LoadingChanged?.Invoke();
Expand Down
Loading
Loading