Skip to content

Commit 3c819eb

Browse files
authored
Avoid multiple quick notifications of in progress swaps in chat (#60)
1 parent 254f94e commit 3c819eb

File tree

1 file changed

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

1 file changed

+13
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ import (
3030
"github.com/code-payments/code-server/pkg/usdc"
3131
)
3232

33+
var (
34+
swapNotificationTimeByOwner = make(map[string]time.Time)
35+
)
36+
3337
func (s *transactionServer) Swap(streamer transactionpb.Transaction_SwapServer) error {
3438
ctx, cancel := context.WithTimeout(streamer.Context(), s.conf.swapTimeout.Get(streamer.Context()))
3539
defer cancel()
@@ -415,6 +419,15 @@ func (s *transactionServer) Swap(streamer transactionpb.Transaction_SwapServer)
415419

416420
// Temporary for manual USDC deposit flow
417421
func (s *transactionServer) bestEffortNotifyUserOfSwapInProgress(ctx context.Context, owner *common.Account) {
422+
// Avoid spamming users chat messages due to retries of the Swap RPC within
423+
// small periods of time. Implementation isn't perfect, but we'll be updating
424+
// notifications later anyways.
425+
lastNotificationTs, ok := swapNotificationTimeByOwner[owner.PublicKey().ToBase58()]
426+
if ok && time.Since(lastNotificationTs) < time.Minute {
427+
return
428+
}
429+
swapNotificationTimeByOwner[owner.PublicKey().ToBase58()] = time.Now()
430+
418431
chatMessage, err := chat_util.NewUsdcBeingConvertedMessage()
419432
if err != nil {
420433
return

0 commit comments

Comments
 (0)