@@ -16,8 +16,10 @@ import (
1616 transactionpb "github.com/code-payments/code-protobuf-api/generated/go/transaction/v2"
1717
1818 "github.com/code-payments/code-server/pkg/code/balance"
19+ chat_util "github.com/code-payments/code-server/pkg/code/chat"
1920 "github.com/code-payments/code-server/pkg/code/common"
2021 "github.com/code-payments/code-server/pkg/code/data/account"
22+ push_util "github.com/code-payments/code-server/pkg/code/push"
2123 currency_lib "github.com/code-payments/code-server/pkg/currency"
2224 "github.com/code-payments/code-server/pkg/grpc/client"
2325 "github.com/code-payments/code-server/pkg/jupiter"
@@ -28,6 +30,10 @@ import (
2830 "github.com/code-payments/code-server/pkg/usdc"
2931)
3032
33+ var (
34+ swapNotificationTimeByOwner = make (map [string ]time.Time )
35+ )
36+
3137func (s * transactionServer ) Swap (streamer transactionpb.Transaction_SwapServer ) error {
3238 ctx , cancel := context .WithTimeout (streamer .Context (), s .conf .swapTimeout .Get (streamer .Context ()))
3339 defer cancel ()
@@ -364,6 +370,8 @@ func (s *transactionServer) Swap(streamer transactionpb.Transaction_SwapServer)
364370
365371 log .Debug ("submitted transaction" )
366372
373+ s .bestEffortNotifyUserOfSwapInProgress (ctx , owner )
374+
367375 if ! initiateReq .WaitForBlockchainStatus {
368376 err = streamer .Send (& transactionpb.SwapResponse {
369377 Response : & transactionpb.SwapResponse_Success_ {
@@ -475,6 +483,38 @@ func (s *transactionServer) validateSwap(
475483 return nil
476484}
477485
486+ func (s * transactionServer ) bestEffortNotifyUserOfSwapInProgress (ctx context.Context , owner * common.Account ) {
487+ // Avoid spamming users chat messages due to retries of the Swap RPC within
488+ // small periods of time. Implementation isn't perfect, but we'll be updating
489+ // notifications later anyways.
490+ lastNotificationTs , ok := swapNotificationTimeByOwner [owner .PublicKey ().ToBase58 ()]
491+ if ok && time .Since (lastNotificationTs ) < time .Minute {
492+ return
493+ }
494+ swapNotificationTimeByOwner [owner .PublicKey ().ToBase58 ()] = time .Now ()
495+
496+ chatMessage , err := chat_util .NewUsdcBeingConvertedMessage ()
497+ if err != nil {
498+ return
499+ }
500+
501+ canPush , err := chat_util .SendKinPurchasesMessage (ctx , s .data , owner , chatMessage )
502+ if err != nil {
503+ return
504+ }
505+
506+ if canPush {
507+ push_util .SendChatMessagePushNotification (
508+ ctx ,
509+ s .data ,
510+ s .pusher ,
511+ chat_util .KinPurchasesName ,
512+ owner ,
513+ chatMessage ,
514+ )
515+ }
516+ }
517+
478518func (s * transactionServer ) mustLoadSwapSubsidizer (ctx context.Context ) {
479519 log := s .log .WithFields (logrus.Fields {
480520 "method" : "mustLoadSwapSubsidizer" ,
0 commit comments