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

fix: send notification when fees are exactly at threshold #13

Merged
merged 2 commits into from
Feb 13, 2025
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
6 changes: 3 additions & 3 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ async def notify_subscription(

url = encode_url_params(from_asset, to_asset)
threshold_msg = (
f"went below {subscription.fee_threshold}%"
if get_fee(fees, subscription) < subscription.fee_threshold
f"has reached {subscription.fee_threshold}%"
if get_fee(fees, subscription) <= subscription.fee_threshold
else f"are above {subscription.fee_threshold}% again"
)
message = f"Fees for {from_asset} -> {to_asset} {threshold_msg}: {url}"
Expand All @@ -63,7 +63,7 @@ def check_subscription(
if fee is None or previous_fee is None:
return False
fee_threshold = subscription.fee_threshold
below = fee < fee_threshold and previous_fee >= fee_threshold
below = fee <= fee_threshold and previous_fee > fee_threshold
above = fee > fee_threshold and previous_fee <= fee_threshold
return below or above

Expand Down
2 changes: 1 addition & 1 deletion db.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __str__(self):
return f"Subscription(chat_id={self.chat_id}, from_asset={self.from_asset}, to_asset={self.to_asset}, fee_threshold={self.fee_threshold})"

def pretty_string(self):
return f"{self.from_asset} -> {self.to_asset} below {self.fee_threshold}%"
return f"{self.from_asset} -> {self.to_asset} at {self.fee_threshold}%"


def db_session(context: ContextTypes.DEFAULT_TYPE) -> AsyncSession:
Expand Down
18 changes: 18 additions & 0 deletions test_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
@pytest.mark.parametrize(
"current_fees, previous_fees, from_asset, to_asset, threshold, expected, test_description",
[
(
{"BTC": {"LN": 1.2}},
{"BTC": {"LN": 1.0}},
"BTC",
"LN",
1.0,
True,
"fee exactly at threshold",
),
(
{"BTC": {"LN": 0.8}},
{"BTC": {"LN": 1.2}},
Expand All @@ -26,6 +35,15 @@
True,
"LN to BTC fee goes above threshold",
),
(
{"LN": {"BTC": 0.8}},
{"LN": {"BTC": 1.0}},
"LN",
"BTC",
1.0,
False,
"fee goes back to threshold",
),
(
{"L-BTC": {"RBTC": 1.5}},
{"L-BTC": {"RBTC": 1.3}},
Expand Down
5 changes: 2 additions & 3 deletions tests/e2e/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ async def select_subscription(
await conv.send_message("/mysubscriptions")
my_subscriptions = await conv.get_response()
assert "You are subscribed" in my_subscriptions.text
text = f"{send_asset} -> {receive_asset}"
button = get_button_with_text(my_subscriptions, f"{send_asset} -> {receive_asset}")
if threshold:
text += f" below {threshold}%"
button = get_button_with_text(my_subscriptions, text)
assert threshold in button.text

await button.click()
await wait()
Expand Down