xync-bot 0.3.24.dev11__py3-none-any.whl → 0.3.24.dev12__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of xync-bot might be problematic. Click here for more details.
- xync_bot/routers/pay/dep.py +66 -20
- xync_bot/routers/pay/handler.py +2 -3
- xync_bot/routers/pay/window.py +21 -25
- {xync_bot-0.3.24.dev11.dist-info → xync_bot-0.3.24.dev12.dist-info}/METADATA +1 -1
- {xync_bot-0.3.24.dev11.dist-info → xync_bot-0.3.24.dev12.dist-info}/RECORD +7 -7
- {xync_bot-0.3.24.dev11.dist-info → xync_bot-0.3.24.dev12.dist-info}/WHEEL +0 -0
- {xync_bot-0.3.24.dev11.dist-info → xync_bot-0.3.24.dev12.dist-info}/top_level.txt +0 -0
xync_bot/routers/pay/dep.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import logging
|
|
1
2
|
from asyncio import gather
|
|
2
3
|
from enum import IntEnum
|
|
3
4
|
|
|
@@ -206,10 +207,16 @@ async def edt(msg: Message, txt: str, rm: InlineKeyboardMarkup):
|
|
|
206
207
|
print(msg.bot.store.perm.msg_id, e)
|
|
207
208
|
|
|
208
209
|
|
|
209
|
-
async def
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
210
|
+
async def xync_have_coin_amount(store: Store) -> bool:
|
|
211
|
+
assets = await models.Asset.filter(
|
|
212
|
+
addr__coin_id=store.pay.t_coin_id, addr__ex_id=store.pay.t_ex_id, addr__actor__user__role__in=Role.ADMIN
|
|
213
|
+
)
|
|
214
|
+
return store.pay.amount <= sum(a.free for a in assets)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
async def client_have_coin_amount(store: Store) -> bool:
|
|
218
|
+
assets = await models.Asset.filter(addr__coin_id=store.pay.t_coin_id, addr__actor_id__in=store.perm.actors.values())
|
|
219
|
+
return store.pay.amount <= sum(a.free for a in assets)
|
|
213
220
|
|
|
214
221
|
|
|
215
222
|
async def need_ppo(store: Store):
|
|
@@ -223,22 +230,61 @@ async def need_ppo(store: Store):
|
|
|
223
230
|
return 1
|
|
224
231
|
|
|
225
232
|
|
|
226
|
-
async def
|
|
233
|
+
async def client_target_repr(store: Store) -> tuple[models.Addr | models.Cred, str]:
|
|
234
|
+
if store.pay.t_ex_id:
|
|
235
|
+
addr_to = (
|
|
236
|
+
await models.Addr.filter(
|
|
237
|
+
actor__ex_id=store.pay.t_ex_id, coin_id=store.pay.t_coin_id, actor__user=store.perm.user
|
|
238
|
+
)
|
|
239
|
+
.prefetch_related("actor")
|
|
240
|
+
.first()
|
|
241
|
+
)
|
|
242
|
+
ex, coin = store.glob.exs[store.pay.s_ex_id], store.glob.coins[store.pay.s_coin_id]
|
|
243
|
+
if not addr_to:
|
|
244
|
+
logging.error(f"No {coin} addr in {ex} for user: {store.perm.user.username_id}")
|
|
245
|
+
return addr_to, f"{coin} на {ex} по id: `{addr_to.actor.exid}`"
|
|
246
|
+
# иначе: реквизиты для фиата
|
|
247
|
+
cur, pm = store.glob.curs[store.pay.t_cur_id], store.glob.pmcurs[store.pay.t_pmcur_id]
|
|
248
|
+
cred = store.perm.creds[store.pay.cred_id]
|
|
249
|
+
return cred, f"{cur.ticker} на {pm} по номеру: {cred.repr()}"
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
async def get_merch_target(store: Store) -> tuple[models.Addr | models.Cred, str]:
|
|
227
253
|
if store.pay.s_ex_id:
|
|
228
|
-
addr_in =
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
254
|
+
addr_in = (
|
|
255
|
+
await models.Addr.filter(
|
|
256
|
+
actor__ex_id=store.pay.s_ex_id, coin_id=store.pay.s_coin_id, actor__user__role__gte=Role.ADMIN
|
|
257
|
+
)
|
|
258
|
+
.prefetch_related("actor")
|
|
259
|
+
.first()
|
|
234
260
|
)
|
|
261
|
+
ex, coin = store.glob.exs[store.pay.s_ex_id], store.glob.coins[store.pay.s_coin_id]
|
|
262
|
+
if not addr_in:
|
|
263
|
+
logging.error(f"No {coin} addr in {ex}")
|
|
264
|
+
return addr_in, f"{coin} на {ex} по id: `{addr_in.actor.exid}`"
|
|
265
|
+
# иначе: реквизиты для фиатной оплаты
|
|
266
|
+
s_pmcur = await models.Pmcur.get(id=store.pay.s_pmcur_id).prefetch_related("pm__grp")
|
|
267
|
+
cred = await models.Cred.filter(
|
|
268
|
+
**({"pmcur__pm__grp": s_pmcur.pm.grp} if s_pmcur.pm.grp else {"pmcur_id": store.pay.s_pmcur_id}),
|
|
269
|
+
person__user__role__gte=Role.ADMIN,
|
|
270
|
+
).first() # todo: order by fiat.target-fiat.amount
|
|
271
|
+
cur, pm = store.glob.curs[store.pay.s_cur_id], store.glob.pmcurs[store.pay.s_pmcur_id]
|
|
272
|
+
if not cred:
|
|
273
|
+
logging.error(f"No {cur.ticker} cred for {pm}")
|
|
274
|
+
return cred, f"{cur.ticker} на {pm} по номеру: {cred.repr()}"
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def fmt_sec(sec: int):
|
|
278
|
+
days = sec // (24 * 3600)
|
|
279
|
+
sec %= 24 * 3600
|
|
280
|
+
hours = sec // 3600
|
|
281
|
+
sec %= 3600
|
|
282
|
+
minutes = sec // 60
|
|
283
|
+
sec %= 60
|
|
284
|
+
|
|
285
|
+
if days > 0:
|
|
286
|
+
return f"{days}д {hours:02d}:{minutes:02d}:{sec:02d}"
|
|
287
|
+
elif hours > 0:
|
|
288
|
+
return f"{hours:02d}:{minutes:02d}:{sec:02d}"
|
|
235
289
|
else:
|
|
236
|
-
|
|
237
|
-
cred_id = await models.Cred.get( # todo: extend cred search conditions
|
|
238
|
-
**({"pmcur__pm__grp": s_pmcur.pm.grp} if s_pmcur.pm.grp else {"pmcur_id": store.pay.s_pmcur_id}),
|
|
239
|
-
person__user__role__gte=Role.ADMIN,
|
|
240
|
-
)
|
|
241
|
-
return cred_id, (
|
|
242
|
-
f"{store.glob.curs[store.pay.s_cur_id]} на {store.glob.pmcurs[store.pay.s_pmcur_id]} "
|
|
243
|
-
f"по номеру: `{cred_id.detail}`, имя: {cred_id.name}{cred_id.extra and f' ({cred_id.extra})' or ''}"
|
|
244
|
-
)
|
|
290
|
+
return f"{minutes:02d}:{sec:02d}"
|
xync_bot/routers/pay/handler.py
CHANGED
|
@@ -22,6 +22,7 @@ async def h_start(msg: Message):
|
|
|
22
22
|
await gather(window.type_select(msg), dlt(msg))
|
|
23
23
|
store.perm.user = await models.User.get(username_id=msg.from_user.id)
|
|
24
24
|
store.perm.creds, store.perm.cur_creds = await fill_creds(store.perm.user.person_id)
|
|
25
|
+
store.perm.actors = await fill_actors(store.perm.user.person_id)
|
|
25
26
|
|
|
26
27
|
|
|
27
28
|
@pay.callback_query(cd.MoneyType.filter(F.is_fiat))
|
|
@@ -35,9 +36,7 @@ async def h_got_fiat_type(query: CallbackQuery, bot: PGram):
|
|
|
35
36
|
async def h_got_crypto_type(query: CallbackQuery, bot: PGram):
|
|
36
37
|
"""Step 2c: Select coin"""
|
|
37
38
|
bot.store.curr.is_fiat = False
|
|
38
|
-
|
|
39
|
-
fill_actors(bot.store.perm.user.person_id), window.coin_select(query.message), ans(query, "Понял, крипта")
|
|
40
|
-
)
|
|
39
|
+
await gather(window.coin_select(query.message), ans(query, "Понял, крипта"))
|
|
41
40
|
|
|
42
41
|
|
|
43
42
|
@pay.callback_query(cd.Coin.filter())
|
xync_bot/routers/pay/window.py
CHANGED
|
@@ -6,7 +6,15 @@ from aiogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
|
|
|
6
6
|
from aiogram.utils.keyboard import InlineKeyboardBuilder
|
|
7
7
|
from xync_schema import models
|
|
8
8
|
|
|
9
|
-
from xync_bot.routers.pay.dep import
|
|
9
|
+
from xync_bot.routers.pay.dep import (
|
|
10
|
+
edt,
|
|
11
|
+
need_ppo,
|
|
12
|
+
Store,
|
|
13
|
+
get_merch_target,
|
|
14
|
+
fmt_sec,
|
|
15
|
+
client_have_coin_amount,
|
|
16
|
+
client_target_repr,
|
|
17
|
+
)
|
|
10
18
|
|
|
11
19
|
from xync_bot.routers.pay import cd, dep
|
|
12
20
|
|
|
@@ -174,7 +182,7 @@ async def set_ppo(msg: Message):
|
|
|
174
182
|
|
|
175
183
|
async def set_urgency(msg: Message):
|
|
176
184
|
store: Store = msg.bot.store
|
|
177
|
-
if not store.curr.is_fiat or
|
|
185
|
+
if not store.curr.is_fiat or await client_have_coin_amount(store):
|
|
178
186
|
return await create_payreq(msg) # next
|
|
179
187
|
builder = InlineKeyboardBuilder()
|
|
180
188
|
(
|
|
@@ -183,7 +191,7 @@ async def set_urgency(msg: Message):
|
|
|
183
191
|
.button(text="30 мин", callback_data=cd.Time(minutes=30))
|
|
184
192
|
.button(text="3 часа", callback_data=cd.Time(minutes=180))
|
|
185
193
|
.button(text="сутки", callback_data=cd.Time(minutes=60 * 24))
|
|
186
|
-
.button(text="Назад к
|
|
194
|
+
.button(text="Назад к выбору платежной\nсистемы для отправки", callback_data=cd.PayNav(to=cd.PayStep.s_pm))
|
|
187
195
|
.button(text="Домой", callback_data=cd.PayNav(to=cd.PayStep.t_type))
|
|
188
196
|
.adjust(2, 2, 1, 1, 1)
|
|
189
197
|
)
|
|
@@ -201,41 +209,29 @@ async def create_payreq(msg: Message):
|
|
|
201
209
|
user=store.perm.user,
|
|
202
210
|
)
|
|
203
211
|
store.pay.pr_id = pay_req.id
|
|
204
|
-
inp, txt = await
|
|
212
|
+
inp, txt = await get_merch_target(store)
|
|
213
|
+
ccred, ctxt = await client_target_repr(store)
|
|
214
|
+
txt += f"\nИ получите {store.pay.amount} {ctxt} в течение {fmt_sec(store.pay.urg * 60)}"
|
|
215
|
+
if store.pay.ppo > 1:
|
|
216
|
+
txt += f" максимум {store.pay.ppo} платежами"
|
|
205
217
|
rm = InlineKeyboardMarkup(
|
|
206
218
|
inline_keyboard=[
|
|
207
219
|
[InlineKeyboardButton(text="Отправил", callback_data=cd.Action(act=cd.ActionType.sent).pack())],
|
|
208
220
|
]
|
|
209
221
|
)
|
|
210
|
-
await edt(msg, f"
|
|
222
|
+
await edt(msg, f"Отправьте {100500} " + txt, rm) # todo: get rate
|
|
211
223
|
|
|
212
|
-
# create_task(window.run_timer(msg))
|
|
224
|
+
# create_task(window.run_timer(msg))В
|
|
213
225
|
|
|
214
226
|
|
|
215
227
|
async def run_timer(message, state: FSMContext):
|
|
216
228
|
builder = InlineKeyboardBuilder()
|
|
217
229
|
builder.button(text="Платеж получен", callback_data=cd.Action(act=cd.ActionType.received))
|
|
218
230
|
|
|
219
|
-
|
|
220
|
-
seconds = data * 60
|
|
221
|
-
|
|
222
|
-
def format(sec):
|
|
223
|
-
days = sec // (24 * 3600)
|
|
224
|
-
sec %= 24 * 3600
|
|
225
|
-
hours = sec // 3600
|
|
226
|
-
sec %= 3600
|
|
227
|
-
minutes = sec // 60
|
|
228
|
-
sec %= 60
|
|
229
|
-
|
|
230
|
-
if days > 0:
|
|
231
|
-
return f"{days}д {hours:02d}:{minutes:02d}:{sec:02d}"
|
|
232
|
-
elif hours > 0:
|
|
233
|
-
return f"{hours:02d}:{minutes:02d}:{sec:02d}"
|
|
234
|
-
else:
|
|
235
|
-
return f"{minutes:02d}:{sec:02d}"
|
|
231
|
+
seconds = await state.get_value("timer") * 60
|
|
236
232
|
|
|
237
233
|
try:
|
|
238
|
-
await message.edit_text(f"⏳ Осталось {
|
|
234
|
+
await message.edit_text(f"⏳ Осталось {fmt_sec(seconds)}", reply_markup=builder.as_markup())
|
|
239
235
|
except Exception:
|
|
240
236
|
return
|
|
241
237
|
|
|
@@ -243,7 +239,7 @@ async def run_timer(message, state: FSMContext):
|
|
|
243
239
|
await sleep(1)
|
|
244
240
|
seconds -= 1
|
|
245
241
|
try:
|
|
246
|
-
await message.edit_text(f"⏳ Осталось {
|
|
242
|
+
await message.edit_text(f"⏳ Осталось {fmt_sec(seconds)}", reply_markup=builder.as_markup())
|
|
247
243
|
await state.update_data(timer=seconds)
|
|
248
244
|
except Exception:
|
|
249
245
|
break
|
|
@@ -11,10 +11,10 @@ xync_bot/routers/xicon.png,sha256=O57_kvzhVcCXSoGYZ61m0dW9pizY6gxR8Yj5aeCP0RQ,42
|
|
|
11
11
|
xync_bot/routers/cond/__init__.py,sha256=It4djVO8AxXL1I76buRz8yYF12dsjXaa4WNtPdb7CFc,4333
|
|
12
12
|
xync_bot/routers/cond/func.py,sha256=m0NWDKunbqDJQmhv_5UnpjxjRzn78GFG94ThOFLVlQo,4720
|
|
13
13
|
xync_bot/routers/pay/cd.py,sha256=yu5U0j8f1RncfagiuycCeUFWwZtLmbT-Mx8G8whfdg8,927
|
|
14
|
-
xync_bot/routers/pay/dep.py,sha256=
|
|
15
|
-
xync_bot/routers/pay/handler.py,sha256=
|
|
16
|
-
xync_bot/routers/pay/window.py,sha256
|
|
17
|
-
xync_bot-0.3.24.
|
|
18
|
-
xync_bot-0.3.24.
|
|
19
|
-
xync_bot-0.3.24.
|
|
20
|
-
xync_bot-0.3.24.
|
|
14
|
+
xync_bot/routers/pay/dep.py,sha256=u1RCKl3gultJ509W9gbl-ixCCS6B9lgkrDYa_I8Uu2g,10249
|
|
15
|
+
xync_bot/routers/pay/handler.py,sha256=aT_Oc_q-h_dX3pU2KhmX7PdRZUeLIuIpagTbBY45GJs,10207
|
|
16
|
+
xync_bot/routers/pay/window.py,sha256=-scDDorW2qy9K1gNuGHZVBTaNIdd-7Hh64ZHCFizNVs,11256
|
|
17
|
+
xync_bot-0.3.24.dev12.dist-info/METADATA,sha256=MhjS0p9XZSsZJBIwSCYrrr-h8oWNXx2a_0cctuB9FF8,752
|
|
18
|
+
xync_bot-0.3.24.dev12.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
19
|
+
xync_bot-0.3.24.dev12.dist-info/top_level.txt,sha256=O2IjMc1ryAf0rwIXWohSNT5Kzcs9johgKRDz8lCC0rs,9
|
|
20
|
+
xync_bot-0.3.24.dev12.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|