Skip to content

Commit

Permalink
Dynamically determine if order supports escrow
Browse files Browse the repository at this point in the history
Signed-off-by: alfred richardsn <rchrdsn@protonmail.ch>
  • Loading branch information
r4rdsn committed Nov 22, 2019
1 parent 4bba917 commit 34734a2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
17 changes: 11 additions & 6 deletions src/handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from pymongo.cursor import Cursor

from src.config import Config
from src.escrow import get_escrow_instance

from src.bot import ( # noqa: F401, noreorder
dp,
Expand Down Expand Up @@ -368,13 +369,17 @@ async def show_order(
),
),
)
elif order.get("escrow"):
keyboard.row(
types.InlineKeyboardButton(
_("Escrow", locale=locale),
callback_data="escrow {} sum_buy 0".format(order["_id"]),
elif "price_sell" in order:
if (
get_escrow_instance(order["buy"]) is not None
or get_escrow_instance(order["sell"]) is not None
):
keyboard.row(
types.InlineKeyboardButton(
_("Escrow", locale=locale),
callback_data="escrow {} sum_buy 0".format(order["_id"]),
)
)
)

keyboard.row(
types.InlineKeyboardButton(
Expand Down
6 changes: 0 additions & 6 deletions src/handlers/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
from src.bot import dp
from src.bot import tg
from src.database import database
from src.escrow import get_escrow_instance
from src.handlers.base import inline_control_buttons
from src.handlers.base import private_handler
from src.handlers.base import show_order
Expand Down Expand Up @@ -598,11 +597,6 @@ async def set_order(order: MutableMapping[str, Any], chat_id: int):
order["price_buy"] = Decimal128(
normalize(order["sum_buy"].to_decimal() / order["sum_sell"].to_decimal())
)
if "price_sell" in order:
if get_escrow_instance(order["buy"]) is not None:
order["escrow"] = "buy"
elif get_escrow_instance(order["sell"]) is not None:
order["escrow"] = "sell"

inserted_order = await database.orders.insert_one(order)
order["_id"] = inserted_order.inserted_id
Expand Down
3 changes: 2 additions & 1 deletion src/handlers/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from src.config import Config
from src.database import database
from src.database import STATE_KEY
from src.escrow import get_escrow_instance
from src.escrow.escrow_offer import EscrowOffer
from src.handlers.base import orders_list
from src.handlers.base import private_handler
Expand Down Expand Up @@ -342,7 +343,7 @@ async def escrow_button(call: types.CallbackQuery, order: OrderType):
"order": order["_id"],
"buy": order["buy"],
"sell": order["sell"],
"type": order["escrow"],
"type": "buy" if get_escrow_instance(order["buy"]) else "sell",
"time": time(),
"sum_currency": currency_arg,
"init": {
Expand Down

0 comments on commit 34734a2

Please sign in to comment.