@@ -11,16 +11,21 @@ import (
11
11
"github.com/sirupsen/logrus"
12
12
"google.golang.org/grpc/codes"
13
13
"google.golang.org/grpc/status"
14
+ "google.golang.org/protobuf/proto"
14
15
16
+ chatpb "github.com/code-payments/code-protobuf-api/generated/go/chat/v1"
15
17
commonpb "github.com/code-payments/code-protobuf-api/generated/go/common/v1"
16
18
transactionpb "github.com/code-payments/code-protobuf-api/generated/go/transaction/v2"
17
19
18
20
"github.com/code-payments/code-server/pkg/code/balance"
19
21
chat_util "github.com/code-payments/code-server/pkg/code/chat"
20
22
"github.com/code-payments/code-server/pkg/code/common"
21
23
"github.com/code-payments/code-server/pkg/code/data/account"
24
+ "github.com/code-payments/code-server/pkg/code/data/chat"
25
+ "github.com/code-payments/code-server/pkg/code/localization"
22
26
push_util "github.com/code-payments/code-server/pkg/code/push"
23
27
currency_lib "github.com/code-payments/code-server/pkg/currency"
28
+ "github.com/code-payments/code-server/pkg/database/query"
24
29
"github.com/code-payments/code-server/pkg/grpc/client"
25
30
"github.com/code-payments/code-server/pkg/jupiter"
26
31
"github.com/code-payments/code-server/pkg/kin"
@@ -493,6 +498,31 @@ func (s *transactionServer) bestEffortNotifyUserOfSwapInProgress(ctx context.Con
493
498
}
494
499
swapNotificationTimeByOwner [owner .PublicKey ().ToBase58 ()] = time .Now ()
495
500
501
+ chatId := chat_util .GetKinPurchasesChatId (owner )
502
+
503
+ // Inspect the chat history for a USDC deposited message. If that message
504
+ // doesn't exist, then avoid sending the swap in progress chat message, since
505
+ // it can lead to user confusion.
506
+ chatMessageRecords , err := s .data .GetAllChatMessages (ctx , chatId , query .WithDirection (query .Descending ), query .WithLimit (1 ))
507
+ switch err {
508
+ case nil :
509
+ var protoChatMessage chatpb.ChatMessage
510
+ err := proto .Unmarshal (chatMessageRecords [0 ].Data , & protoChatMessage )
511
+ if err != nil {
512
+ return
513
+ }
514
+
515
+ switch typed := protoChatMessage .Content [0 ].Type .(type ) {
516
+ case * chatpb.Content_Localized :
517
+ if typed .Localized .KeyOrText != localization .ChatMessageUsdcDeposited {
518
+ return
519
+ }
520
+ }
521
+ case chat .ErrMessageNotFound :
522
+ default :
523
+ return
524
+ }
525
+
496
526
chatMessage , err := chat_util .NewUsdcBeingConvertedMessage ()
497
527
if err != nil {
498
528
return
0 commit comments