Skip to content

Commit

Permalink
Merge pull request #1623 from MixinNetwork/feature/alert
Browse files Browse the repository at this point in the history
Feature/alert
  • Loading branch information
over140 authored Oct 11, 2024
2 parents aa1c3a3 + e17dea7 commit 6738658
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 81 deletions.
26 changes: 13 additions & 13 deletions Mixin/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,20 @@
"alert_limit_exceeded" = "The total number of price alerts for all currencies cannot exceed %d.";
"alert_per_asset_limit_exceeded" = "You can create a maximum of %d price alerts for each trading pair.";
"alert_type" = "Alert Type";
"alert_type_percentage_decreased" = "24h fall exceeds";
"alert_type_percentage_decreased_description" = "Triggered when the 24h fall exceeds your set price change";
"alert_type_percentage_decreased_value" = "24h fall exceeds %@";
"alert_type_percentage_increased" = "24h rise exceeds";
"alert_type_percentage_increased_description" = "Triggered when the 24h rise exceeds your set price change";
"alert_type_percentage_increased_value" = "24h rise exceeds %@";
"alert_type_price_decreased" = "Price drops to";
"alert_type_price_decreased_description" = "Triggered when the last price drops to your set price";
"alert_type_price_decreased_value" = "Price drops to %@";
"alert_type_price_increased" = "Price rises above";
"alert_type_price_increased_description" = "Triggered when the last price rises above your set price";
"alert_type_price_increased_value" = "Price rises above %@";
"alert_type_percentage_decreased" = "24h loss exceeds";
"alert_type_percentage_decreased_description" = "Triggered when the 24h loss exceeds your set price change. ";
"alert_type_percentage_decreased_value" = "24h loss exceeds %@";
"alert_type_percentage_increased" = "24h gain exceeds";
"alert_type_percentage_increased_description" = "Triggered when the 24h gain exceeds your set price change. ";
"alert_type_percentage_increased_value" = "24h gain exceeds %@";
"alert_type_price_decreased" = "Price moves below";
"alert_type_price_decreased_description" = "Triggered when the last price moves below your set price.";
"alert_type_price_decreased_value" = "Price moves below %@";
"alert_type_price_increased" = "Price moves above";
"alert_type_price_increased_description" = "Triggered when the last price moves above your set price.";
"alert_type_price_increased_value" = "Price moves above %@";
"alert_type_price_reached" = "Price reaches";
"alert_type_price_reached_description" = "Triggered when the last price reaches your set price";
"alert_type_price_reached_description" = "Triggered when the last price moves above or below your set price.";
"alert_type_price_reached_value" = "Price reaches %@";
"alert_value" = "Value";
"all" = "All";
Expand Down
26 changes: 13 additions & 13 deletions Mixin/Resources/es.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,20 @@
"alert_limit_exceeded" = "The total number of price alerts for all currencies cannot exceed %d.";
"alert_per_asset_limit_exceeded" = "You can create a maximum of %d price alerts for each trading pair.";
"alert_type" = "Alert Type";
"alert_type_percentage_decreased" = "24h fall exceeds";
"alert_type_percentage_decreased_description" = "Triggered when the 24h fall exceeds your set price change";
"alert_type_percentage_decreased_value" = "24h fall exceeds %@";
"alert_type_percentage_increased" = "24h rise exceeds";
"alert_type_percentage_increased_description" = "Triggered when the 24h rise exceeds your set price change";
"alert_type_percentage_increased_value" = "24h rise exceeds %@";
"alert_type_price_decreased" = "Price drops to";
"alert_type_price_decreased_description" = "Triggered when the last price drops to your set price";
"alert_type_price_decreased_value" = "Price drops to %@";
"alert_type_price_increased" = "Price rises above";
"alert_type_price_increased_description" = "Triggered when the last price rises above your set price";
"alert_type_price_increased_value" = "Price rises above %@";
"alert_type_percentage_decreased" = "24h loss exceeds";
"alert_type_percentage_decreased_description" = "Triggered when the 24h loss exceeds your set price change. ";
"alert_type_percentage_decreased_value" = "24h loss exceeds %@";
"alert_type_percentage_increased" = "24h gain exceeds";
"alert_type_percentage_increased_description" = "Triggered when the 24h gain exceeds your set price change. ";
"alert_type_percentage_increased_value" = "24h gain exceeds %@";
"alert_type_price_decreased" = "Price moves below";
"alert_type_price_decreased_description" = "Triggered when the last price moves below your set price.";
"alert_type_price_decreased_value" = "Price moves below %@";
"alert_type_price_increased" = "Price moves above";
"alert_type_price_increased_description" = "Triggered when the last price moves above your set price.";
"alert_type_price_increased_value" = "Price moves above %@";
"alert_type_price_reached" = "Price reaches";
"alert_type_price_reached_description" = "Triggered when the last price reaches your set price";
"alert_type_price_reached_description" = "Triggered when the last price moves above or below your set price.";
"alert_type_price_reached_value" = "Price reaches %@";
"alert_value" = "Value";
"all" = "Todo";
Expand Down
26 changes: 13 additions & 13 deletions Mixin/Resources/ja.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,20 @@
"alert_limit_exceeded" = "The total number of price alerts for all currencies cannot exceed %d.";
"alert_per_asset_limit_exceeded" = "You can create a maximum of %d price alerts for each trading pair.";
"alert_type" = "Alert Type";
"alert_type_percentage_decreased" = "24h fall exceeds";
"alert_type_percentage_decreased_description" = "Triggered when the 24h fall exceeds your set price change";
"alert_type_percentage_decreased_value" = "24h fall exceeds %@";
"alert_type_percentage_increased" = "24h rise exceeds";
"alert_type_percentage_increased_description" = "Triggered when the 24h rise exceeds your set price change";
"alert_type_percentage_increased_value" = "24h rise exceeds %@";
"alert_type_price_decreased" = "Price drops to";
"alert_type_price_decreased_description" = "Triggered when the last price drops to your set price";
"alert_type_price_decreased_value" = "Price drops to %@";
"alert_type_price_increased" = "Price rises above";
"alert_type_price_increased_description" = "Triggered when the last price rises above your set price";
"alert_type_price_increased_value" = "Price rises above %@";
"alert_type_percentage_decreased" = "24h loss exceeds";
"alert_type_percentage_decreased_description" = "Triggered when the 24h loss exceeds your set price change. ";
"alert_type_percentage_decreased_value" = "24h loss exceeds %@";
"alert_type_percentage_increased" = "24h gain exceeds";
"alert_type_percentage_increased_description" = "Triggered when the 24h gain exceeds your set price change. ";
"alert_type_percentage_increased_value" = "24h gain exceeds %@";
"alert_type_price_decreased" = "Price moves below";
"alert_type_price_decreased_description" = "Triggered when the last price moves below your set price.";
"alert_type_price_decreased_value" = "Price moves below %@";
"alert_type_price_increased" = "Price moves above";
"alert_type_price_increased_description" = "Triggered when the last price moves above your set price.";
"alert_type_price_increased_value" = "Price moves above %@";
"alert_type_price_reached" = "Price reaches";
"alert_type_price_reached_description" = "Triggered when the last price reaches your set price";
"alert_type_price_reached_description" = "Triggered when the last price moves above or below your set price.";
"alert_type_price_reached_value" = "Price reaches %@";
"alert_value" = "Value";
"all" = "すべて";
Expand Down
26 changes: 13 additions & 13 deletions Mixin/Resources/ru.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,20 @@
"alert_limit_exceeded" = "The total number of price alerts for all currencies cannot exceed %d.";
"alert_per_asset_limit_exceeded" = "You can create a maximum of %d price alerts for each trading pair.";
"alert_type" = "Alert Type";
"alert_type_percentage_decreased" = "24h fall exceeds";
"alert_type_percentage_decreased_description" = "Triggered when the 24h fall exceeds your set price change";
"alert_type_percentage_decreased_value" = "24h fall exceeds %@";
"alert_type_percentage_increased" = "24h rise exceeds";
"alert_type_percentage_increased_description" = "Triggered when the 24h rise exceeds your set price change";
"alert_type_percentage_increased_value" = "24h rise exceeds %@";
"alert_type_price_decreased" = "Price drops to";
"alert_type_price_decreased_description" = "Triggered when the last price drops to your set price";
"alert_type_price_decreased_value" = "Price drops to %@";
"alert_type_price_increased" = "Price rises above";
"alert_type_price_increased_description" = "Triggered when the last price rises above your set price";
"alert_type_price_increased_value" = "Price rises above %@";
"alert_type_percentage_decreased" = "24h loss exceeds";
"alert_type_percentage_decreased_description" = "Triggered when the 24h loss exceeds your set price change. ";
"alert_type_percentage_decreased_value" = "24h loss exceeds %@";
"alert_type_percentage_increased" = "24h gain exceeds";
"alert_type_percentage_increased_description" = "Triggered when the 24h gain exceeds your set price change. ";
"alert_type_percentage_increased_value" = "24h gain exceeds %@";
"alert_type_price_decreased" = "Price moves below";
"alert_type_price_decreased_description" = "Triggered when the last price moves below your set price.";
"alert_type_price_decreased_value" = "Price moves below %@";
"alert_type_price_increased" = "Price moves above";
"alert_type_price_increased_description" = "Triggered when the last price moves above your set price.";
"alert_type_price_increased_value" = "Price moves above %@";
"alert_type_price_reached" = "Price reaches";
"alert_type_price_reached_description" = "Triggered when the last price reaches your set price";
"alert_type_price_reached_description" = "Triggered when the last price moves above or below your set price.";
"alert_type_price_reached_value" = "Price reaches %@";
"alert_value" = "Value";
"all" = "Все";
Expand Down
10 changes: 5 additions & 5 deletions Mixin/Resources/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@
"alert_per_asset_limit_exceeded" = "每个交易对最多可创建 %d 个价格预警。";
"alert_type" = "预警类型";
"alert_type_percentage_decreased" = "24 小时跌幅超过";
"alert_type_percentage_decreased_description" = "过去 24 小时内跌幅超过或等于设置比例时触发";
"alert_type_percentage_decreased_description" = "过去 24 小时内跌幅超过或等于设置比例时触发";
"alert_type_percentage_decreased_value" = "24 小时跌幅超过 %@";
"alert_type_percentage_increased" = "24 小时涨幅超过";
"alert_type_percentage_increased_description" = "过去 24 小时内涨幅超过或等于设置比例时触发";
"alert_type_percentage_increased_description" = "过去 24 小时内涨幅超过或等于设置比例时触发";
"alert_type_percentage_increased_value" = "24 小时涨幅超过 %@";
"alert_type_price_decreased" = "价格跌到";
"alert_type_price_decreased_description" = "最新价格小于或等于设置价格时触发";
"alert_type_price_decreased_description" = "最新价格小于或等于设置价格时触发";
"alert_type_price_decreased_value" = "价格跌到 %@";
"alert_type_price_increased" = "价格涨到";
"alert_type_price_increased_description" = "最新价格大于或等于设置价格时触发";
"alert_type_price_increased_description" = "最新价格大于或等于设置价格时触发";
"alert_type_price_increased_value" = "价格涨到 %@";
"alert_type_price_reached" = "价格到达";
"alert_type_price_reached_description" = "最新价格达到设置价格时触发";
"alert_type_price_reached_description" = "最新价格等于、超过或跌破设置价格时触发。";
"alert_type_price_reached_value" = "价格达到 %@";
"alert_value" = "数值";
"all" = "全部";
Expand Down
10 changes: 5 additions & 5 deletions Mixin/Resources/zh-Hant.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,19 @@
"alert_per_asset_limit_exceeded" = "每個交易對最多可建立 %d 個價格預警。";
"alert_type" = "預警型別";
"alert_type_percentage_decreased" = "24 小時跌幅超過";
"alert_type_percentage_decreased_description" = "過去 24 小時內跌幅超過或等於設定比例時觸發";
"alert_type_percentage_decreased_description" = "過去 24 小時內跌幅超過或等於設定比例時觸發";
"alert_type_percentage_decreased_value" = "24 小時跌幅超過 %@";
"alert_type_percentage_increased" = "24 小時漲幅超過";
"alert_type_percentage_increased_description" = "過去 24 小時內漲幅超過或等於設定比例時觸發";
"alert_type_percentage_increased_description" = "過去 24 小時內漲幅超過或等於設定比例時觸發";
"alert_type_percentage_increased_value" = "24 小時漲幅超過 %@";
"alert_type_price_decreased" = "價格跌到";
"alert_type_price_decreased_description" = "最新價格小於或等於設定價格時觸發";
"alert_type_price_decreased_description" = "最新價格小於或等於設定價格時觸發";
"alert_type_price_decreased_value" = "價格跌到 %@";
"alert_type_price_increased" = "價格漲到";
"alert_type_price_increased_description" = "最新價格大於或等於設定價格時觸發";
"alert_type_price_increased_description" = "最新價格大於或等於設定價格時觸發";
"alert_type_price_increased_value" = "價格漲到 %@";
"alert_type_price_reached" = "價格到達";
"alert_type_price_reached_description" = "最新價格達到設定價格時觸發";
"alert_type_price_reached_description" = "最新價格等於、超過或跌破設定價格時觸發。";
"alert_type_price_reached_value" = "價格達到 %@";
"alert_value" = "數值";
"all" = "全部";
Expand Down
7 changes: 5 additions & 2 deletions Mixin/Service/API/RouteAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ final class RouteAPI {
) {
request(
method: .post,
path: "/prices/alerts/\(alertID)?action=\(action.rawValue)",
path: "/prices/alerts/\(alertID)",
with: ["action": action.rawValue],
completion: completion
)
}
Expand All @@ -136,13 +137,14 @@ final class RouteAPI {
completion: @escaping (MixinAPI.Result<MarketAlert>) -> Void
) {
let parameters = [
"action": "update",
"type": alert.type.rawValue,
"frequency": alert.frequency.rawValue,
"value": alert.value
]
request(
method: .post,
path: "/prices/alerts/\(alert.alertID)?action=update",
path: "/prices/alerts/\(alert.alertID)",
with: parameters,
completion: completion
)
Expand All @@ -155,6 +157,7 @@ final class RouteAPI {
request(
method: .get,
path: "/prices/alerts",
queue: queue,
completion: completion
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ class AddMarketAlertViewController: KeyboardBasedLayoutViewController {
formatter.string(from: coin.decimalPrice as NSDecimalNumber)
}

private let changePercentages: [Decimal] = [
private let increasePrecentageLimitation = PercentageLimitation(min: 0.0001, max: 10)
private let decreasePrecentageLimitation = PercentageLimitation(min: 0.0001, max: 0.9999)
private let presetChangePercentages: [Decimal] = [
-0.2, -0.1, -0.05, 0.05, 0.1, 0.2
]

Expand Down Expand Up @@ -86,7 +88,7 @@ class AddMarketAlertViewController: KeyboardBasedLayoutViewController {
override func viewDidLoad() {
super.viewDidLoad()

for (i, percentage) in changePercentages.enumerated() {
for (i, percentage) in presetChangePercentages.enumerated() {
let button = PresetPercentageButton(type: .system)
let title = NumberFormatter.percentage.string(decimal: percentage)
button.setTitle(title, for: .normal)
Expand Down Expand Up @@ -229,14 +231,20 @@ class AddMarketAlertViewController: KeyboardBasedLayoutViewController {
nil
}
case .percentageIncreased:
if value < 0.001 || value > 1000 {
R.string.localizable.price_increase_invalid("10%", "1000%")
if !increasePrecentageLimitation.contains(value: value / 100) {
R.string.localizable.price_increase_invalid(
increasePrecentageLimitation.minRepresentation,
increasePrecentageLimitation.maxRepresentation
)
} else {
nil
}
case .percentageDecreased:
if value < 0.001 || value > 1000 {
R.string.localizable.price_decrease_invalid("10%", "1000%")
if !decreasePrecentageLimitation.contains(value: value / 100) {
R.string.localizable.price_increase_invalid(
decreasePrecentageLimitation.minRepresentation,
decreasePrecentageLimitation.maxRepresentation
)
} else {
nil
}
Expand Down Expand Up @@ -287,6 +295,25 @@ extension AddMarketAlertViewController {

}

private struct PercentageLimitation {

let min: Decimal
let max: Decimal

var minRepresentation: String {
NumberFormatter.percentage.string(decimal: min) ?? "\(min)"
}

var maxRepresentation: String {
NumberFormatter.percentage.string(decimal: max) ?? "\(max)"
}

func contains(value: Decimal) -> Bool {
value >= min && value <= max
}

}

@objc private func keyboardWillShow(_ notification: Notification) {
beginInputButton.isHidden = true
}
Expand All @@ -299,7 +326,7 @@ extension AddMarketAlertViewController {
}

@objc private func loadPresetPercentage(_ sender: UIButton) {
let percentage = changePercentages[sender.tag]
let percentage = presetChangePercentages[sender.tag]
let value = switch alertType.valueType {
case .absolute:
coin.decimalPrice * (1 + percentage)
Expand Down Expand Up @@ -328,7 +355,7 @@ extension AddMarketAlertViewController {
self.alertType = type
alertTypeLabel.text = type.name
inputTextField.text = inputText
let center = changePercentages.firstIndex(where: { $0 > 0 }) ?? 0
let center = presetChangePercentages.firstIndex(where: { $0 > 0 }) ?? 0
switch type {
case .priceReached:
presetPercentageWrapperView.isHidden = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ final class TokenPriceChartCell: UITableViewCell {
}
}

func updatePriceAndChange(price: String?, points: [ChartView.Point]?) {
func updatePriceAndChangeByMarket(price: String?, points: [ChartView.Point]?) {
priceLabel.text = price
guard let points, points.count >= 2 else {
changeLabel.alpha = 0
Expand All @@ -129,7 +129,7 @@ final class TokenPriceChartCell: UITableViewCell {
updateChange(base: base, now: now)
}

func updatePriceAndChange(base: ChartView.Point, now: ChartView.Point) {
func updatePriceAndChangeByChart(base: ChartView.Point, now: ChartView.Point) {
priceLabel.text = CurrencyFormatter.localizedString(
from: now.value * Currency.current.decimalRate,
format: .fiatMoneyPrice,
Expand Down
Loading

0 comments on commit 6738658

Please sign in to comment.