Compare commits

...
1 Commits
Author SHA1 Message Date
callebtc 48c4bcb759 diffs 2022-02-26 10:48:20 +03:00
4 changed files with 18 additions and 21 deletions
+1 -1
View File
@@ -188,7 +188,7 @@ func (bot *TipBot) enterAmountHandler(ctx context.Context, m *tb.Message) (conte
if err != nil { if err != nil {
return ctx, err return ctx, err
} }
LnurlWithdrawState := sn.(*LnurlWithdrawState) LnurlWithdrawState := sn.(LnurlWithdrawState)
LnurlWithdrawState.Amount = amount * 1000 // mSat LnurlWithdrawState.Amount = amount * 1000 // mSat
// add result to persistent struct // add result to persistent struct
runtime.IgnoreError(LnurlWithdrawState.Set(LnurlWithdrawState, bot.Bunt)) runtime.IgnoreError(LnurlWithdrawState.Set(LnurlWithdrawState, bot.Bunt))
+8 -10
View File
@@ -34,13 +34,13 @@ type LnurlPayState struct {
// lnurlPayHandler1 is invoked when the first lnurl response was a lnurlpay response // lnurlPayHandler1 is invoked when the first lnurl response was a lnurlpay response
// at this point, the user hans't necessarily entered an amount yet // at this point, the user hans't necessarily entered an amount yet
func (bot *TipBot) lnurlPayHandler(ctx context.Context, m *tb.Message, payParams LnurlPayState) { func (bot *TipBot) lnurlPayHandler(ctx context.Context, m *tb.Message, payParams LnurlPayState) (context.Context, error) {
user := LoadUser(ctx) user := LoadUser(ctx)
if user.Wallet == nil { if user.Wallet == nil {
return return ctx, errors.Create(errors.UserNoWalletError)
} }
// object that holds all information about the send payment // object that holds all information about the send payment
id := fmt.Sprintf("lnurlp-%d-%s", m.Sender.ID, RandStringRunes(5)) id := fmt.Sprintf("lnurlp:%d:%s", m.Sender.ID, RandStringRunes(5))
lnurlPayState := &LnurlPayState{ lnurlPayState := &LnurlPayState{
Base: storage.New(storage.ID(id)), Base: storage.New(storage.ID(id)),
From: user, From: user,
@@ -77,7 +77,7 @@ func (bot *TipBot) lnurlPayHandler(ctx context.Context, m *tb.Message, payParams
log.Warnf("[lnurlPayHandler] Error: %s", err.Error()) log.Warnf("[lnurlPayHandler] Error: %s", err.Error())
bot.trySendMessage(m.Sender, fmt.Sprintf(Translate(ctx, "lnurlInvalidAmountRangeMessage"), lnurlPayState.LNURLPayParams.MinSendable/1000, lnurlPayState.LNURLPayParams.MaxSendable/1000)) bot.trySendMessage(m.Sender, fmt.Sprintf(Translate(ctx, "lnurlInvalidAmountRangeMessage"), lnurlPayState.LNURLPayParams.MinSendable/1000, lnurlPayState.LNURLPayParams.MaxSendable/1000))
ResetUserState(user, bot) ResetUserState(user, bot)
return return ctx, err
} }
// set also amount in the state of the user // set also amount in the state of the user
lnurlPayState.Amount = amount * 1000 // save as mSat lnurlPayState.Amount = amount * 1000 // save as mSat
@@ -87,12 +87,11 @@ func (bot *TipBot) lnurlPayHandler(ctx context.Context, m *tb.Message, payParams
// now we actualy check whether the amount was in the command and if not, ask for it // now we actualy check whether the amount was in the command and if not, ask for it
if lnurlPayState.LNURLPayParams.MinSendable == lnurlPayState.LNURLPayParams.MaxSendable { if lnurlPayState.LNURLPayParams.MinSendable == lnurlPayState.LNURLPayParams.MaxSendable {
amount = lnurlPayState.LNURLPayParams.MaxSendable / 1000 lnurlPayState.Amount = lnurlPayState.LNURLPayParams.MaxSendable // save as mSat
lnurlPayState.Amount = amount * 1000 // save as mSat
} else if amount_err != nil || amount < 1 { } else if amount_err != nil || amount < 1 {
// // no amount was entered, set user state and ask for amount // // no amount was entered, set user state and ask for amount
bot.askForAmount(ctx, id, "LnurlPayState", lnurlPayState.LNURLPayParams.MinSendable, lnurlPayState.LNURLPayParams.MaxSendable, m.Text) bot.askForAmount(ctx, id, "LnurlPayState", lnurlPayState.LNURLPayParams.MinSendable, lnurlPayState.LNURLPayParams.MaxSendable, m.Text)
return return ctx, nil
} }
// We need to save the pay state in the user state so we can load the payment in the next handler // We need to save the pay state in the user state so we can load the payment in the next handler
@@ -100,12 +99,11 @@ func (bot *TipBot) lnurlPayHandler(ctx context.Context, m *tb.Message, payParams
if err != nil { if err != nil {
log.Errorf("[lnurlPayHandler] Error: %s", err.Error()) log.Errorf("[lnurlPayHandler] Error: %s", err.Error())
// bot.trySendMessage(m.Sender, err.Error()) // bot.trySendMessage(m.Sender, err.Error())
return return ctx, err
} }
SetUserState(user, bot, lnbits.UserHasEnteredAmount, string(paramsJson)) SetUserState(user, bot, lnbits.UserHasEnteredAmount, string(paramsJson))
// directly go to confirm // directly go to confirm
bot.lnurlPayHandlerSend(ctx, m) return bot.lnurlPayHandlerSend(ctx, m)
return
} }
// lnurlPayHandlerSend is invoked when the user has delivered an amount and is ready to pay // lnurlPayHandlerSend is invoked when the user has delivered an amount and is ready to pay
+7 -8
View File
@@ -58,13 +58,13 @@ func (bot *TipBot) editSingleButton(ctx context.Context, m *tb.Message, message
// lnurlWithdrawHandler is invoked when the first lnurl response was a lnurl-withdraw response // lnurlWithdrawHandler is invoked when the first lnurl response was a lnurl-withdraw response
// at this point, the user hans't necessarily entered an amount yet // at this point, the user hans't necessarily entered an amount yet
func (bot *TipBot) lnurlWithdrawHandler(ctx context.Context, m *tb.Message, withdrawParams LnurlWithdrawState) { func (bot *TipBot) lnurlWithdrawHandler(ctx context.Context, m *tb.Message, withdrawParams LnurlWithdrawState) (context.Context, error) {
user := LoadUser(ctx) user := LoadUser(ctx)
if user.Wallet == nil { if user.Wallet == nil {
return return ctx, errors.Create(errors.UserNoWalletError)
} }
// object that holds all information about the send payment // object that holds all information about the send payment
id := fmt.Sprintf("lnurlw-%d-%s", m.Sender.ID, RandStringRunes(5)) id := fmt.Sprintf("lnurlw:%d:%s", m.Sender.ID, RandStringRunes(5))
LnurlWithdrawState := LnurlWithdrawState{ LnurlWithdrawState := LnurlWithdrawState{
Base: storage.New(storage.ID(id)), Base: storage.New(storage.ID(id)),
From: user, From: user,
@@ -84,7 +84,7 @@ func (bot *TipBot) lnurlWithdrawHandler(ctx context.Context, m *tb.Message, with
log.Warnf("[lnurlWithdrawHandler] Error: %s", err.Error()) log.Warnf("[lnurlWithdrawHandler] Error: %s", err.Error())
bot.trySendMessage(m.Sender, fmt.Sprintf(Translate(ctx, "lnurlInvalidAmountRangeMessage"), LnurlWithdrawState.LNURLWithdrawResponse.MinWithdrawable/1000, LnurlWithdrawState.LNURLWithdrawResponse.MaxWithdrawable/1000)) bot.trySendMessage(m.Sender, fmt.Sprintf(Translate(ctx, "lnurlInvalidAmountRangeMessage"), LnurlWithdrawState.LNURLWithdrawResponse.MinWithdrawable/1000, LnurlWithdrawState.LNURLWithdrawResponse.MaxWithdrawable/1000))
ResetUserState(user, bot) ResetUserState(user, bot)
return return ctx, err
} }
// if no amount is entered, and if only one amount is possible, we use it // if no amount is entered, and if only one amount is possible, we use it
@@ -103,7 +103,7 @@ func (bot *TipBot) lnurlWithdrawHandler(ctx context.Context, m *tb.Message, with
if amount_err != nil || amount < 1 { if amount_err != nil || amount < 1 {
// // no amount was entered, set user state and ask for amount // // no amount was entered, set user state and ask for amount
bot.askForAmount(ctx, id, "LnurlWithdrawState", LnurlWithdrawState.LNURLWithdrawResponse.MinWithdrawable, LnurlWithdrawState.LNURLWithdrawResponse.MaxWithdrawable, m.Text) bot.askForAmount(ctx, id, "LnurlWithdrawState", LnurlWithdrawState.LNURLWithdrawResponse.MinWithdrawable, LnurlWithdrawState.LNURLWithdrawResponse.MaxWithdrawable, m.Text)
return return ctx, nil
} }
// We need to save the pay state in the user state so we can load the payment in the next handler // We need to save the pay state in the user state so we can load the payment in the next handler
@@ -111,12 +111,11 @@ func (bot *TipBot) lnurlWithdrawHandler(ctx context.Context, m *tb.Message, with
if err != nil { if err != nil {
log.Errorf("[lnurlWithdrawHandler] Error: %s", err.Error()) log.Errorf("[lnurlWithdrawHandler] Error: %s", err.Error())
// bot.trySendMessage(m.Sender, err.Error()) // bot.trySendMessage(m.Sender, err.Error())
return return ctx, err
} }
SetUserState(user, bot, lnbits.UserHasEnteredAmount, string(paramsJson)) SetUserState(user, bot, lnbits.UserHasEnteredAmount, string(paramsJson))
// directly go to confirm // directly go to confirm
bot.lnurlWithdrawHandlerWithdraw(ctx, m) return bot.lnurlWithdrawHandlerWithdraw(ctx, m)
return
} }
// lnurlWithdrawHandlerWithdraw is invoked when the user has delivered an amount and is ready to pay // lnurlWithdrawHandlerWithdraw is invoked when the user has delivered an amount and is ready to pay
+2 -2
View File
@@ -107,13 +107,13 @@ func (bot *TipBot) lnurlHandler(ctx context.Context, m *tb.Message) (context.Con
bot.trySendMessage(m.Sender, fmt.Sprintf("`%s`", payParams.LNURLPayParams.Metadata.Description)) bot.trySendMessage(m.Sender, fmt.Sprintf("`%s`", payParams.LNURLPayParams.Metadata.Description))
} }
// ask whether to make payment // ask whether to make payment
bot.lnurlPayHandler(ctx, m, *payParams) return bot.lnurlPayHandler(ctx, m, *payParams)
case lnurl.LNURLWithdrawResponse: case lnurl.LNURLWithdrawResponse:
withdrawParams := LnurlWithdrawState{LNURLWithdrawResponse: params.(lnurl.LNURLWithdrawResponse)} withdrawParams := LnurlWithdrawState{LNURLWithdrawResponse: params.(lnurl.LNURLWithdrawResponse)}
log.Infof("[LNURL-w] %s", withdrawParams.LNURLWithdrawResponse.Callback) log.Infof("[LNURL-w] %s", withdrawParams.LNURLWithdrawResponse.Callback)
bot.tryDeleteMessage(statusMsg) bot.tryDeleteMessage(statusMsg)
bot.lnurlWithdrawHandler(ctx, m, withdrawParams) return bot.lnurlWithdrawHandler(ctx, m, withdrawParams)
default: default:
if err == nil { if err == nil {
err = fmt.Errorf("invalid LNURL type") err = fmt.Errorf("invalid LNURL type")