Skip to content

Commit 8c782ed

Browse files
authored
Improve error logging for swap in progress chat message (#93)
1 parent c979063 commit 8c782ed

File tree

1 file changed

+13
-8
lines changed
  • pkg/code/server/grpc/transaction/v2

1 file changed

+13
-8
lines changed

pkg/code/server/grpc/transaction/v2/swap.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,10 @@ func (s *transactionServer) Swap(streamer transactionpb.Transaction_SwapServer)
375375

376376
log.Debug("submitted transaction")
377377

378-
s.bestEffortNotifyUserOfSwapInProgress(ctx, owner)
378+
err = s.bestEffortNotifyUserOfSwapInProgress(ctx, owner)
379+
if err != nil {
380+
log.WithError(err).Warn("failure notifying user of swap in progress")
381+
}
379382

380383
if !initiateReq.WaitForBlockchainStatus {
381384
err = streamer.Send(&transactionpb.SwapResponse{
@@ -488,13 +491,13 @@ func (s *transactionServer) validateSwap(
488491
return nil
489492
}
490493

491-
func (s *transactionServer) bestEffortNotifyUserOfSwapInProgress(ctx context.Context, owner *common.Account) {
494+
func (s *transactionServer) bestEffortNotifyUserOfSwapInProgress(ctx context.Context, owner *common.Account) error {
492495
// Avoid spamming users chat messages due to retries of the Swap RPC within
493496
// small periods of time. Implementation isn't perfect, but we'll be updating
494497
// notifications later anyways.
495498
lastNotificationTs, ok := swapNotificationTimeByOwner[owner.PublicKey().ToBase58()]
496499
if ok && time.Since(lastNotificationTs) < time.Minute {
497-
return
500+
return nil
498501
}
499502
swapNotificationTimeByOwner[owner.PublicKey().ToBase58()] = time.Now()
500503

@@ -509,28 +512,28 @@ func (s *transactionServer) bestEffortNotifyUserOfSwapInProgress(ctx context.Con
509512
var protoChatMessage chatpb.ChatMessage
510513
err := proto.Unmarshal(chatMessageRecords[0].Data, &protoChatMessage)
511514
if err != nil {
512-
return
515+
return errors.Wrap(err, "error unmarshalling proto chat message")
513516
}
514517

515518
switch typed := protoChatMessage.Content[0].Type.(type) {
516519
case *chatpb.Content_Localized:
517520
if typed.Localized.KeyOrText != localization.ChatMessageUsdcDeposited {
518-
return
521+
return nil
519522
}
520523
}
521524
case chat.ErrMessageNotFound:
522525
default:
523-
return
526+
return errors.Wrap(err, "error fetching chat messages")
524527
}
525528

526529
chatMessage, err := chat_util.NewUsdcBeingConvertedMessage()
527530
if err != nil {
528-
return
531+
return errors.Wrap(err, "error creating chat message")
529532
}
530533

531534
canPush, err := chat_util.SendKinPurchasesMessage(ctx, s.data, owner, chatMessage)
532535
if err != nil {
533-
return
536+
return errors.Wrap(err, "error sending chat message")
534537
}
535538

536539
if canPush {
@@ -543,6 +546,8 @@ func (s *transactionServer) bestEffortNotifyUserOfSwapInProgress(ctx context.Con
543546
chatMessage,
544547
)
545548
}
549+
550+
return nil
546551
}
547552

548553
func (s *transactionServer) mustLoadSwapSubsidizer(ctx context.Context) {

0 commit comments

Comments
 (0)