Skip to content

Commit f8cafbb

Browse files
authored
Support Buy and Sell notifications in ActivityFeed service (#12)
1 parent 711cc42 commit f8cafbb

File tree

4 files changed

+27
-17
lines changed

4 files changed

+27
-17
lines changed

activity/localization.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ func InjectLocalizedText(ctx context.Context, ocpData ocp_data.Provider, userOwn
5454
}
5555
}
5656

57+
case *activitypb.Notification_BoughtCrypto:
58+
localizedText = "Purchased"
59+
60+
case *activitypb.Notification_SoldCrypto:
61+
localizedText = "Sold"
62+
5763
default:
5864
return errors.New("unsupported notification type")
5965
}

activity/server.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ import (
1515

1616
"github.com/code-payments/flipcash2-server/auth"
1717
"github.com/code-payments/flipcash2-server/model"
18+
ocp_query "github.com/code-payments/ocp-server/database/query"
1819
ocp_common "github.com/code-payments/ocp-server/ocp/common"
1920
ocp_data "github.com/code-payments/ocp-server/ocp/data"
2021
ocp_intent "github.com/code-payments/ocp-server/ocp/data/intent"
2122
ocp_transaction "github.com/code-payments/ocp-server/ocp/rpc/transaction"
22-
ocp_currency "github.com/code-payments/ocp-server/currency"
23-
ocp_query "github.com/code-payments/ocp-server/database/query"
2423
"github.com/code-payments/ocp-server/pointer"
2524
)
2625

@@ -275,6 +274,8 @@ func (s *Server) toLocalizedNotifications(ctx context.Context, log *zap.Logger,
275274
if !isClaimed {
276275
notification.State = activitypb.NotificationState_NOTIFICATION_STATE_PENDING
277276
}
277+
} else if intentMetadata.IsSwapSell {
278+
notification.AdditionalMetadata = &activitypb.Notification_SoldCrypto{SoldCrypto: &activitypb.SoldCryptoNotificationMetadata{}}
278279
} else if intentMetadata.IsWithdrawal {
279280
notification.AdditionalMetadata = &activitypb.Notification_WithdrewCrypto{WithdrewCrypto: &activitypb.WithdrewCryptoNotificationMetadata{}}
280281
} else {
@@ -308,16 +309,21 @@ func (s *Server) toLocalizedNotifications(ctx context.Context, log *zap.Logger,
308309
intentMetadata := intentRecord.ExternalDepositMetadata
309310

310311
// Hide small, potentially spam deposits
311-
if intentMetadata.UsdMarketValue < 0.01 {
312+
if !intentMetadata.IsSwapBuy && intentMetadata.UsdMarketValue < 0.01 {
312313
continue
313314
}
314315

315316
notification.PaymentAmount = &commonpb.CryptoPaymentAmount{
316-
Currency: string(ocp_currency.USD),
317-
NativeAmount: intentMetadata.UsdMarketValue,
317+
Currency: string(intentMetadata.ExchangeCurrency),
318+
NativeAmount: intentMetadata.NativeAmount,
318319
Quarks: intentMetadata.Quantity,
319320
}
320-
notification.AdditionalMetadata = &activitypb.Notification_DepositedCrypto{DepositedCrypto: &activitypb.DepositedCryptoNotificationMetadata{}}
321+
322+
if intentMetadata.IsSwapBuy {
323+
notification.AdditionalMetadata = &activitypb.Notification_BoughtCrypto{BoughtCrypto: &activitypb.BoughtCryptoNotificationMetadata{}}
324+
} else {
325+
notification.AdditionalMetadata = &activitypb.Notification_DepositedCrypto{DepositedCrypto: &activitypb.DepositedCryptoNotificationMetadata{}}
326+
}
321327

322328
default:
323329
continue

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ go 1.25.0
55
require (
66
firebase.google.com/go/v4 v4.18.0
77
github.com/ReneKroon/ttlcache v1.7.0
8-
github.com/code-payments/flipcash2-protobuf-api v0.1.0
9-
github.com/code-payments/ocp-protobuf-api v0.7.0
10-
github.com/code-payments/ocp-server v0.14.0
8+
github.com/code-payments/flipcash2-protobuf-api v0.2.0
9+
github.com/code-payments/ocp-protobuf-api v0.10.0
10+
github.com/code-payments/ocp-server v0.24.0
1111
github.com/devsisters/go-applereceipt v0.0.0-20240805020915-fa22a0160fc2
1212
github.com/georgysavva/scany/v2 v2.1.4
1313
github.com/google/uuid v1.6.0

go.sum

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@ github.com/cockroachdb/cockroach-go/v2 v2.2.0 h1:/5znzg5n373N/3ESjHF5SMLxiW4RKB0
4040
github.com/cockroachdb/cockroach-go/v2 v2.2.0/go.mod h1:u3MiKYGupPPjkn3ozknpMUpxPaNLTFWAya419/zv6eI=
4141
github.com/code-payments/code-vm-indexer v1.2.0 h1:rSHpBMiT9BKgmKcXg/VIoi/h0t7jNxGx07Qz59m+6Q0=
4242
github.com/code-payments/code-vm-indexer v1.2.0/go.mod h1:vn91YN2qNqb+gGJeZe2+l+TNxVmEEiRHXXnIn2Y40h8=
43-
github.com/code-payments/flipcash2-protobuf-api v0.1.0 h1:SJ8beRISJzLiwYdLEDFrMibb2SSCzyTFhFwv7N2+Itw=
44-
github.com/code-payments/flipcash2-protobuf-api v0.1.0/go.mod h1:s/1pOsb4FTRD+LcvRKGjfmm6ygRS/m1ep34EIW0fuDs=
45-
github.com/code-payments/ocp-protobuf-api v0.7.0 h1:pHIVYXmDus32LEzaj92qDWKYrPawuzBIJ+Xlzzf9udg=
46-
github.com/code-payments/ocp-protobuf-api v0.7.0/go.mod h1:tw6BooY5a8l6CtSZnKOruyKII0W04n89pcM4BizrgG8=
47-
github.com/code-payments/ocp-server v0.13.0 h1:5OGnwrAosQq3ZKs03SJVUN9ghl9h8aRbnPRjhu67W40=
48-
github.com/code-payments/ocp-server v0.13.0/go.mod h1:UWdvoBiMc8Ltp1QedZFy+XPsLTAxIOCnTqALJfXfKi8=
49-
github.com/code-payments/ocp-server v0.14.0 h1:If3P9paQy0Md6okTAj3yXtsk7Pme162ZQDx4Z3zQhaA=
50-
github.com/code-payments/ocp-server v0.14.0/go.mod h1:UWdvoBiMc8Ltp1QedZFy+XPsLTAxIOCnTqALJfXfKi8=
43+
github.com/code-payments/flipcash2-protobuf-api v0.2.0 h1:5uL9g0D+WyoCP95rg37CJOPA+a8sPOQrKWrfEEIDM+U=
44+
github.com/code-payments/flipcash2-protobuf-api v0.2.0/go.mod h1:s/1pOsb4FTRD+LcvRKGjfmm6ygRS/m1ep34EIW0fuDs=
45+
github.com/code-payments/ocp-protobuf-api v0.10.0 h1:l9Yh3eXdhvgBQS/evg1HYMERXlr7ymASHekAhW/RUmA=
46+
github.com/code-payments/ocp-protobuf-api v0.10.0/go.mod h1:tw6BooY5a8l6CtSZnKOruyKII0W04n89pcM4BizrgG8=
47+
github.com/code-payments/ocp-server v0.24.0 h1:QF7K3Nbrapl2tXx4EgL3xPWpxqCM+gCNiP2+RralSBM=
48+
github.com/code-payments/ocp-server v0.24.0/go.mod h1:+E1VncCtaZGgvM9wKu+qe/AA+gpcbbpu0BXw76vcD4k=
5149
github.com/containerd/continuity v0.4.3 h1:6HVkalIp+2u1ZLH1J/pYX2oBVXlJZvh1X1A7bEZ9Su8=
5250
github.com/containerd/continuity v0.4.3/go.mod h1:F6PTNCKepoxEaXLQp3wDAjygEnImnZ/7o4JzpodfroQ=
5351
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=

0 commit comments

Comments
 (0)