From 26c47b427c95401865953d34ed0411d4565fe1f7 Mon Sep 17 00:00:00 2001 From: jeffyanta Date: Wed, 29 Apr 2026 13:23:55 -0400 Subject: [PATCH] Handle withdrawals that are swaps in transaction history --- activity/localization.go | 11 +++++++++++ activity/server.go | 17 +++++++++++++---- go.mod | 4 ++-- go.sum | 8 ++++---- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/activity/localization.go b/activity/localization.go index 7f12c72..fe4fcd6 100644 --- a/activity/localization.go +++ b/activity/localization.go @@ -23,6 +23,17 @@ func InjectLocalizedText(ctx context.Context, ocpData ocp_data.Provider, userOwn case *activitypb.Notification_WithdrewCrypto: localizedText = "Withdrew" + switch typed.WithdrewCrypto.SwapState { + case activitypb.SwapState_SWAP_STATE_SUCCEEDED, activitypb.SwapState_SWAP_STATE_NONE: + localizedText = "Withdrew" + case activitypb.SwapState_SWAP_STATE_FAILED: + localizedText = "Withdrawal Failed" + case activitypb.SwapState_SWAP_STATE_PENDING: + localizedText = "Withdrawing" + default: + return errors.New("unsupported swap state") + } + case *activitypb.Notification_DepositedCrypto: localizedText = "Added" diff --git a/activity/server.go b/activity/server.go index 09bb46f..29397fa 100644 --- a/activity/server.go +++ b/activity/server.go @@ -21,6 +21,7 @@ import ( ocp_intent "github.com/code-payments/ocp-server/ocp/data/intent" ocp_swap "github.com/code-payments/ocp-server/ocp/data/swap" "github.com/code-payments/ocp-server/pointer" + "github.com/code-payments/ocp-server/usdc" ) const ( @@ -289,11 +290,19 @@ func (s *Server) toLocalizedNotifications(ctx context.Context, log *zap.Logger, notification.State = activitypb.NotificationState_NOTIFICATION_STATE_PENDING } - notification.AdditionalMetadata = &activitypb.Notification_SoldCrypto{SoldCrypto: &activitypb.SoldCryptoNotificationMetadata{ - SwapState: swapState, - }} + if swapRecord.ToMint == usdc.Mint { + notification.AdditionalMetadata = &activitypb.Notification_WithdrewCrypto{WithdrewCrypto: &activitypb.WithdrewCryptoNotificationMetadata{ + SwapState: swapState, + }} + } else { + notification.AdditionalMetadata = &activitypb.Notification_SoldCrypto{SoldCrypto: &activitypb.SoldCryptoNotificationMetadata{ + SwapState: swapState, + }} + } } else if intentMetadata.IsWithdrawal { - notification.AdditionalMetadata = &activitypb.Notification_WithdrewCrypto{WithdrewCrypto: &activitypb.WithdrewCryptoNotificationMetadata{}} + notification.AdditionalMetadata = &activitypb.Notification_WithdrewCrypto{WithdrewCrypto: &activitypb.WithdrewCryptoNotificationMetadata{ + SwapState: activitypb.SwapState_SWAP_STATE_NONE, + }} } else { notification.AdditionalMetadata = &activitypb.Notification_GaveCrypto{GaveCrypto: &activitypb.GaveCryptoNotificationMetadata{}} } diff --git a/go.mod b/go.mod index 1283bda..92356da 100644 --- a/go.mod +++ b/go.mod @@ -5,9 +5,9 @@ go 1.26.0 require ( firebase.google.com/go/v4 v4.18.0 github.com/ReneKroon/ttlcache v1.7.0 - github.com/code-payments/flipcash2-protobuf-api v1.4.1-0.20260429155359-7b31c1a41cf0 + github.com/code-payments/flipcash2-protobuf-api v1.5.0 github.com/code-payments/ocp-protobuf-api v1.10.0 - github.com/code-payments/ocp-server v1.11.1-0.20260428231936-0d49436103e3 + github.com/code-payments/ocp-server v1.12.0 github.com/devsisters/go-applereceipt v0.0.0-20240805020915-fa22a0160fc2 github.com/georgysavva/scany/v2 v2.1.4 github.com/google/uuid v1.6.0 diff --git a/go.sum b/go.sum index f14295a..7bc0c8c 100644 --- a/go.sum +++ b/go.sum @@ -40,12 +40,12 @@ github.com/cockroachdb/cockroach-go/v2 v2.2.0 h1:/5znzg5n373N/3ESjHF5SMLxiW4RKB0 github.com/cockroachdb/cockroach-go/v2 v2.2.0/go.mod h1:u3MiKYGupPPjkn3ozknpMUpxPaNLTFWAya419/zv6eI= github.com/code-payments/code-vm-indexer v1.2.0 h1:rSHpBMiT9BKgmKcXg/VIoi/h0t7jNxGx07Qz59m+6Q0= github.com/code-payments/code-vm-indexer v1.2.0/go.mod h1:vn91YN2qNqb+gGJeZe2+l+TNxVmEEiRHXXnIn2Y40h8= -github.com/code-payments/flipcash2-protobuf-api v1.4.1-0.20260429155359-7b31c1a41cf0 h1:bGP8kCBfG1wHJ/DVmn025AInix2qthNjxQllmqWNjJA= -github.com/code-payments/flipcash2-protobuf-api v1.4.1-0.20260429155359-7b31c1a41cf0/go.mod h1:s/1pOsb4FTRD+LcvRKGjfmm6ygRS/m1ep34EIW0fuDs= +github.com/code-payments/flipcash2-protobuf-api v1.5.0 h1:3aXu61v5FDsjU9n/w5Z5l31ZEDXJ+JrvNwLZ5JySWZ8= +github.com/code-payments/flipcash2-protobuf-api v1.5.0/go.mod h1:s/1pOsb4FTRD+LcvRKGjfmm6ygRS/m1ep34EIW0fuDs= github.com/code-payments/ocp-protobuf-api v1.10.0 h1:8GEDLh3NShOYz6J7a9VOCqu+xJSd7xR42pewaPfkiE4= github.com/code-payments/ocp-protobuf-api v1.10.0/go.mod h1:tw6BooY5a8l6CtSZnKOruyKII0W04n89pcM4BizrgG8= -github.com/code-payments/ocp-server v1.11.1-0.20260428231936-0d49436103e3 h1:c7f2HxXM7w6yBawsvDnr+DOWEbxEEembhHk/fleKVzY= -github.com/code-payments/ocp-server v1.11.1-0.20260428231936-0d49436103e3/go.mod h1:988X7GYc48DZihgfsv/1rKyFhp+SM00b2uR74NbuMYA= +github.com/code-payments/ocp-server v1.12.0 h1:d1hRjFJzxg7ie/03tpFateW5QKn32m6ic9BKjOSDJvk= +github.com/code-payments/ocp-server v1.12.0/go.mod h1:988X7GYc48DZihgfsv/1rKyFhp+SM00b2uR74NbuMYA= github.com/containerd/continuity v0.4.3 h1:6HVkalIp+2u1ZLH1J/pYX2oBVXlJZvh1X1A7bEZ9Su8= github.com/containerd/continuity v0.4.3/go.mod h1:F6PTNCKepoxEaXLQp3wDAjygEnImnZ/7o4JzpodfroQ= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=