File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
pkg/code/server/grpc/transaction/v2 Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,10 @@ import (
30
30
"github.com/code-payments/code-server/pkg/usdc"
31
31
)
32
32
33
+ var (
34
+ swapNotificationTimeByOwner = make (map [string ]time.Time )
35
+ )
36
+
33
37
func (s * transactionServer ) Swap (streamer transactionpb.Transaction_SwapServer ) error {
34
38
ctx , cancel := context .WithTimeout (streamer .Context (), s .conf .swapTimeout .Get (streamer .Context ()))
35
39
defer cancel ()
@@ -415,6 +419,15 @@ func (s *transactionServer) Swap(streamer transactionpb.Transaction_SwapServer)
415
419
416
420
// Temporary for manual USDC deposit flow
417
421
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
+
418
431
chatMessage , err := chat_util .NewUsdcBeingConvertedMessage ()
419
432
if err != nil {
420
433
return
You can’t perform that action at this time.
0 commit comments