Skip to content

Commit 5184c8e

Browse files
author
jeffyanta
authored
Update swap message timestamp (#114)
1 parent 85b383e commit 5184c8e

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

pkg/code/chat/message_kin_purchases.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func ToUsdcDepositedMessage(signature string, ts time.Time) (*chatpb.ChatMessage
5252

5353
// NewUsdcBeingConvertedMessage generates a new message generated upon initiating
5454
// a USDC swap to be inserted into the Kin Purchases chat.
55-
func NewUsdcBeingConvertedMessage() (*chatpb.ChatMessage, error) {
55+
func NewUsdcBeingConvertedMessage(ts time.Time) (*chatpb.ChatMessage, error) {
5656
messageId, err := common.NewRandomAccount()
5757
if err != nil {
5858
return nil, err
@@ -67,7 +67,7 @@ func NewUsdcBeingConvertedMessage() (*chatpb.ChatMessage, error) {
6767
},
6868
},
6969
}
70-
return newProtoChatMessage(messageId.PublicKey().ToBase58(), content, time.Now())
70+
return newProtoChatMessage(messageId.PublicKey().ToBase58(), content, ts)
7171
}
7272

7373
// ToKinAvailableForUseMessage turns details of a USDC swap transaction into a

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,8 @@ func (s *transactionServer) Swap(streamer transactionpb.Transaction_SwapServer)
365365
// Section: Transaction submission
366366
//
367367

368+
chatMessageTs := time.Now()
369+
368370
_, err = s.data.SubmitBlockchainTransaction(ctx, &txn)
369371
if err != nil {
370372
log.WithError(err).Warn("failure submitting transaction")
@@ -377,7 +379,7 @@ func (s *transactionServer) Swap(streamer transactionpb.Transaction_SwapServer)
377379

378380
log.WithField("txn", base64.StdEncoding.EncodeToString(txn.Marshal())).Info("transaction submitted")
379381

380-
err = s.bestEffortNotifyUserOfSwapInProgress(ctx, owner)
382+
err = s.bestEffortNotifyUserOfSwapInProgress(ctx, owner, chatMessageTs)
381383
if err != nil {
382384
log.WithError(err).Warn("failure notifying user of swap in progress")
383385
}
@@ -493,7 +495,7 @@ func (s *transactionServer) validateSwap(
493495
return nil
494496
}
495497

496-
func (s *transactionServer) bestEffortNotifyUserOfSwapInProgress(ctx context.Context, owner *common.Account) error {
498+
func (s *transactionServer) bestEffortNotifyUserOfSwapInProgress(ctx context.Context, owner *common.Account, ts time.Time) error {
497499
chatId := chat_util.GetKinPurchasesChatId(owner)
498500

499501
// Inspect the chat history for a USDC deposited message. If that message
@@ -519,7 +521,7 @@ func (s *transactionServer) bestEffortNotifyUserOfSwapInProgress(ctx context.Con
519521
return errors.Wrap(err, "error fetching chat messages")
520522
}
521523

522-
chatMessage, err := chat_util.NewUsdcBeingConvertedMessage()
524+
chatMessage, err := chat_util.NewUsdcBeingConvertedMessage(ts)
523525
if err != nil {
524526
return errors.Wrap(err, "error creating chat message")
525527
}

0 commit comments

Comments
 (0)