Skip to content

Commit

Permalink
Fix dublicate callback queries
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 25, 2019
1 parent 9e80d06 commit 7ff186e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/escrow/blockchain/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
from decimal import Decimal
from time import time

from aiogram.dispatcher import FSMContext
from aiogram.types import InlineKeyboardButton
from aiogram.types import InlineKeyboardMarkup
from aiogram.types import ParseMode
from aiogram.utils import markdown
from bson.objectid import ObjectId

from src import states
from src.bot import dp
from src.bot import tg
from src.database import database
from src.i18n import _
Expand Down Expand Up @@ -211,6 +214,8 @@ async def _confirmation_callback(
reply_markup=keyboard,
parse_mode=ParseMode.MARKDOWN,
)
state = FSMContext(dp.storage, other_user["id"], other_user["id"])
await state.set_state(states.Escrow.final_confirmation.state)
return True

await database.escrow.update_one(
Expand Down
10 changes: 8 additions & 2 deletions src/handlers/escrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,8 +790,13 @@ async def edit_keyboard(
await tg.edit_message_reply_markup(chat_id, message_id, reply_markup=keyboard)


@escrow_callback_handler(lambda call: call.data.startswith("tokens_sent "))
async def final_offer_confirmation(call: types.CallbackQuery, offer: EscrowOffer):
@escrow_callback_handler(
lambda call: call.data.startswith("tokens_sent "),
state=states.Escrow.final_confirmation,
)
async def final_offer_confirmation(
call: types.CallbackQuery, state: FSMContext, offer: EscrowOffer
):
"""Ask not escrow asset receiver to confirm transfer."""
if offer.type == "buy":
confirm_user = offer.init
Expand Down Expand Up @@ -830,6 +835,7 @@ async def final_offer_confirmation(call: types.CallbackQuery, offer: EscrowOffer
reply.message_id,
keyboard,
)
await state.finish()
await call.answer()
await tg.send_message(
other_user["id"],
Expand Down
2 changes: 2 additions & 0 deletions src/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class Escrow(StatesGroup):
send_address = State()
#: Send first and last 4 digits of fiat sender's card number.
send_card_number = State()
#: Confirm transfer of not escrow asset.
final_confirmation = State()


#: Ask support a question.
Expand Down

0 comments on commit 7ff186e

Please sign in to comment.