Skip to content

Commit e7031b5

Browse files
authored
update intent DB models to support pay-for-chat intents (#186)
* update intent DB models to support pay-for-chat intents * Update to latest code-protobuf-api, and apply related fixes
1 parent 80b6dd1 commit e7031b5

File tree

15 files changed

+141
-52
lines changed

15 files changed

+141
-52
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ require (
66
firebase.google.com/go/v4 v4.8.0
77
github.com/aws/aws-sdk-go-v2 v0.17.0
88
github.com/bits-and-blooms/bloom/v3 v3.1.0
9-
github.com/code-payments/code-protobuf-api v1.16.6
9+
github.com/code-payments/code-protobuf-api v1.19.0
10+
github.com/dghubble/oauth1 v0.7.3
1011
github.com/emirpasic/gods v1.12.0
1112
github.com/envoyproxy/protoc-gen-validate v1.0.4
1213
github.com/golang-jwt/jwt/v5 v5.0.0
@@ -65,7 +66,6 @@ require (
6566
github.com/coreos/go-semver v0.3.0 // indirect
6667
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
6768
github.com/davecgh/go-spew v1.1.1 // indirect
68-
github.com/dghubble/oauth1 v0.7.3 // indirect
6969
github.com/docker/cli v20.10.7+incompatible // indirect
7070
github.com/docker/docker v20.10.7+incompatible // indirect
7171
github.com/docker/go-connections v0.4.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWH
121121
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
122122
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
123123
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
124-
github.com/code-payments/code-protobuf-api v1.16.6 h1:QCot0U+4Ar5SdSX4v955FORMsd3Qcf0ZgkoqlGJZzu0=
125-
github.com/code-payments/code-protobuf-api v1.16.6/go.mod h1:pHQm75vydD6Cm2qHAzlimW6drysm489Z4tVxC2zHSsU=
124+
github.com/code-payments/code-protobuf-api v1.19.0 h1:md/eJhqltz8dDY0U8hwT/42C3h+kP+W/68D7RMSjqPo=
125+
github.com/code-payments/code-protobuf-api v1.19.0/go.mod h1:pHQm75vydD6Cm2qHAzlimW6drysm489Z4tVxC2zHSsU=
126126
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 h1:NmTXa/uVnDyp0TY5MKi197+3HWcnYWfnHGyaFthlnGw=
127127
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
128128
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=

pkg/code/chat/message_code_team.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ func newIncentiveMessage(localizedTextKey string, intentRecord *intent.Record) (
4848

4949
content := []*chatpb.Content{
5050
{
51-
Type: &chatpb.Content_Localized{
52-
Localized: &chatpb.LocalizedContent{
51+
Type: &chatpb.Content_ServerLocalized{
52+
ServerLocalized: &chatpb.ServerLocalizedContent{
5353
KeyOrText: localizedTextKey,
5454
},
5555
},

pkg/code/chat/message_kin_purchases.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ func SendKinPurchasesMessage(ctx context.Context, data code_data.Provider, recei
4040
func ToUsdcDepositedMessage(signature string, ts time.Time) (*chatpb.ChatMessage, error) {
4141
content := []*chatpb.Content{
4242
{
43-
Type: &chatpb.Content_Localized{
44-
Localized: &chatpb.LocalizedContent{
43+
Type: &chatpb.Content_ServerLocalized{
44+
ServerLocalized: &chatpb.ServerLocalizedContent{
4545
KeyOrText: localization.ChatMessageUsdcDeposited,
4646
},
4747
},
@@ -60,8 +60,8 @@ func NewUsdcBeingConvertedMessage(ts time.Time) (*chatpb.ChatMessage, error) {
6060

6161
content := []*chatpb.Content{
6262
{
63-
Type: &chatpb.Content_Localized{
64-
Localized: &chatpb.LocalizedContent{
63+
Type: &chatpb.Content_ServerLocalized{
64+
ServerLocalized: &chatpb.ServerLocalizedContent{
6565
KeyOrText: localization.ChatMessageUsdcBeingConverted,
6666
},
6767
},
@@ -79,8 +79,8 @@ func ToKinAvailableForUseMessage(signature string, ts time.Time, purchases ...*t
7979

8080
content := []*chatpb.Content{
8181
{
82-
Type: &chatpb.Content_Localized{
83-
Localized: &chatpb.LocalizedContent{
82+
Type: &chatpb.Content_ServerLocalized{
83+
ServerLocalized: &chatpb.ServerLocalizedContent{
8484
KeyOrText: localization.ChatMessageKinAvailableForUse,
8585
},
8686
},

pkg/code/chat/sender_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ func newRandomChatMessage(t *testing.T, contentLength int) *chatpb.ChatMessage {
159159
var content []*chatpb.Content
160160
for i := 0; i < contentLength; i++ {
161161
content = append(content, &chatpb.Content{
162-
Type: &chatpb.Content_Localized{
163-
Localized: &chatpb.LocalizedContent{
162+
Type: &chatpb.Content_ServerLocalized{
163+
ServerLocalized: &chatpb.ServerLocalizedContent{
164164
KeyOrText: fmt.Sprintf("key%d", rand.Uint32()),
165165
},
166166
},

pkg/code/data/intent/intent.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,13 @@ type SendPrivatePaymentMetadata struct {
109109
IsRemoteSend bool
110110
IsMicroPayment bool
111111
IsTip bool
112+
IsChat bool
112113

113114
// Set when IsTip = true
114115
TipMetadata *TipMetadata
116+
117+
// Set when IsChat = true
118+
ChatId string
115119
}
116120

117121
type TipMetadata struct {
@@ -578,8 +582,10 @@ func (m *SendPrivatePaymentMetadata) Clone() SendPrivatePaymentMetadata {
578582
IsRemoteSend: m.IsRemoteSend,
579583
IsMicroPayment: m.IsMicroPayment,
580584
IsTip: m.IsTip,
585+
IsChat: m.IsChat,
581586

582587
TipMetadata: tipMetadata,
588+
ChatId: m.ChatId,
583589
}
584590
}
585591

@@ -605,8 +611,10 @@ func (m *SendPrivatePaymentMetadata) CopyTo(dst *SendPrivatePaymentMetadata) {
605611
dst.IsRemoteSend = m.IsRemoteSend
606612
dst.IsMicroPayment = m.IsMicroPayment
607613
dst.IsTip = m.IsTip
614+
dst.IsChat = m.IsChat
608615

609616
dst.TipMetadata = tipMetadata
617+
dst.ChatId = m.ChatId
610618
}
611619

612620
func (m *SendPrivatePaymentMetadata) Validate() error {
@@ -650,6 +658,14 @@ func (m *SendPrivatePaymentMetadata) Validate() error {
650658
return errors.New("tip metadata can only be set for tips")
651659
}
652660

661+
if m.IsChat {
662+
if len(m.ChatId) == 0 {
663+
return errors.New("chat_id required for chat")
664+
}
665+
} else if m.ChatId != "" {
666+
return errors.New("chat_id can only be set for chats")
667+
}
668+
653669
return nil
654670
}
655671

pkg/code/data/intent/postgres/model.go

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ type intentModel struct {
4949
IsTip bool `db:"is_tip"`
5050
TipPlatform sql.NullInt16 `db:"tip_platform"`
5151
TippedUsername sql.NullString `db:"tipped_username"`
52+
IsChat bool `db:"is_chat"`
53+
ChatId sql.NullString `db:"chat_id"`
5254
RelationshipTo sql.NullString `db:"relationship_to"`
5355
InitiatorPhoneNumber sql.NullString `db:"phone_number"` // todo: rename the DB field to initiator_phone_number
5456
State uint `db:"state"`
@@ -106,6 +108,7 @@ func toIntentModel(obj *intent.Record) (*intentModel, error) {
106108
m.IsRemoteSend = obj.SendPrivatePaymentMetadata.IsRemoteSend
107109
m.IsMicroPayment = obj.SendPrivatePaymentMetadata.IsMicroPayment
108110
m.IsTip = obj.SendPrivatePaymentMetadata.IsTip
111+
m.IsChat = obj.SendPrivatePaymentMetadata.IsChat
109112

110113
if m.IsTip {
111114
m.TipPlatform = sql.NullInt16{
@@ -117,6 +120,13 @@ func toIntentModel(obj *intent.Record) (*intentModel, error) {
117120
String: obj.SendPrivatePaymentMetadata.TipMetadata.Username,
118121
}
119122
}
123+
124+
if m.IsChat {
125+
m.ChatId = sql.NullString{
126+
Valid: true,
127+
String: obj.SendPrivatePaymentMetadata.ChatId,
128+
}
129+
}
120130
case intent.ReceivePaymentsPrivately:
121131
m.Source = obj.ReceivePaymentsPrivatelyMetadata.Source
122132
m.Quantity = obj.ReceivePaymentsPrivatelyMetadata.Quantity
@@ -224,6 +234,7 @@ func fromIntentModel(obj *intentModel) *intent.Record {
224234
IsRemoteSend: obj.IsRemoteSend,
225235
IsMicroPayment: obj.IsMicroPayment,
226236
IsTip: obj.IsTip,
237+
IsChat: obj.IsChat,
227238
}
228239

229240
if record.SendPrivatePaymentMetadata.IsTip {
@@ -232,6 +243,11 @@ func fromIntentModel(obj *intentModel) *intent.Record {
232243
Username: obj.TippedUsername.String,
233244
}
234245
}
246+
247+
if record.SendPrivatePaymentMetadata.IsChat {
248+
record.SendPrivatePaymentMetadata.ChatId = obj.ChatId.String
249+
}
250+
235251
case intent.ReceivePaymentsPrivately:
236252
record.ReceivePaymentsPrivatelyMetadata = &intent.ReceivePaymentsPrivatelyMetadata{
237253
Source: obj.Source,
@@ -300,16 +316,16 @@ func fromIntentModel(obj *intentModel) *intent.Record {
300316
func (m *intentModel) dbSave(ctx context.Context, db *sqlx.DB) error {
301317
return pgutil.ExecuteInTx(ctx, db, sql.LevelDefault, func(tx *sqlx.Tx) error {
302318
query := `INSERT INTO ` + intentTableName + `
303-
(intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, relationship_to, tip_platform, tipped_username, phone_number, state, created_at)
304-
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26)
319+
(intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, is_chat, relationship_to, tip_platform, tipped_username, chat_id, phone_number, state, created_at)
320+
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23, $24, $25, $26, $27, $28)
305321
306322
ON CONFLICT (intent_id)
307323
DO UPDATE
308-
SET state = $25
324+
SET state = $27
309325
WHERE ` + intentTableName + `.intent_id = $1
310326
311327
RETURNING
312-
id, intent_id, intent_type, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, relationship_to, tip_platform, tipped_username, phone_number, state, created_at`
328+
id, intent_id, intent_type, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, is_chat, relationship_to, tip_platform, tipped_username, chat_id, phone_number, state, created_at`
313329

314330
err := tx.QueryRowxContext(
315331
ctx,
@@ -334,9 +350,11 @@ func (m *intentModel) dbSave(ctx context.Context, db *sqlx.DB) error {
334350
m.IsIssuerVoidingGiftCard,
335351
m.IsMicroPayment,
336352
m.IsTip,
353+
m.IsChat,
337354
m.RelationshipTo,
338355
m.TipPlatform,
339356
m.TippedUsername,
357+
m.ChatId,
340358
m.InitiatorPhoneNumber,
341359
m.State,
342360
m.CreatedAt,
@@ -349,7 +367,7 @@ func (m *intentModel) dbSave(ctx context.Context, db *sqlx.DB) error {
349367
func dbGetIntent(ctx context.Context, db *sqlx.DB, intentID string) (*intentModel, error) {
350368
res := &intentModel{}
351369

352-
query := `SELECT id, intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, relationship_to, tip_platform, tipped_username, phone_number, state, created_at
370+
query := `SELECT id, intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, is_chat, relationship_to, tip_platform, tipped_username, chat_id, phone_number, state, created_at
353371
FROM ` + intentTableName + `
354372
WHERE intent_id = $1
355373
LIMIT 1`
@@ -364,7 +382,7 @@ func dbGetIntent(ctx context.Context, db *sqlx.DB, intentID string) (*intentMode
364382
func dbGetLatestByInitiatorAndType(ctx context.Context, db *sqlx.DB, intentType intent.Type, owner string) (*intentModel, error) {
365383
res := &intentModel{}
366384

367-
query := `SELECT id, intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, relationship_to, tip_platform, tipped_username, phone_number, state, created_at
385+
query := `SELECT id, intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, is_chat, relationship_to, tip_platform, tipped_username, chat_id, phone_number, state, created_at
368386
FROM ` + intentTableName + `
369387
WHERE owner = $1 AND intent_type = $2
370388
ORDER BY created_at DESC
@@ -381,7 +399,7 @@ func dbGetLatestByInitiatorAndType(ctx context.Context, db *sqlx.DB, intentType
381399
func dbGetAllByOwner(ctx context.Context, db *sqlx.DB, owner string, cursor q.Cursor, limit uint64, direction q.Ordering) ([]*intentModel, error) {
382400
res := []*intentModel{}
383401

384-
query := `SELECT id, intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, relationship_to, tip_platform, tipped_username, phone_number, state, created_at
402+
query := `SELECT id, intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, is_chat, relationship_to, tip_platform, tipped_username, chat_id, phone_number, state, created_at
385403
FROM ` + intentTableName + `
386404
WHERE (owner = $1 OR destination_owner = $1) AND (intent_type != $2 AND intent_type != $3)
387405
`
@@ -542,7 +560,7 @@ func dbGetNetBalanceFromPrePrivacy2022Intents(ctx context.Context, db *sqlx.DB,
542560
func dbGetLatestSaveRecentRootIntentForTreasury(ctx context.Context, db *sqlx.DB, treasury string) (*intentModel, error) {
543561
res := &intentModel{}
544562

545-
query := `SELECT id, intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, relationship_to, tip_platform, tipped_username, phone_number, state, created_at
563+
query := `SELECT id, intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, is_chat, relationship_to, tip_platform, tipped_username, chat_id, phone_number, state, created_at
546564
FROM ` + intentTableName + `
547565
WHERE treasury_pool = $1 and intent_type = $2
548566
ORDER BY id DESC
@@ -559,7 +577,7 @@ func dbGetLatestSaveRecentRootIntentForTreasury(ctx context.Context, db *sqlx.DB
559577
func dbGetOriginalGiftCardIssuedIntent(ctx context.Context, db *sqlx.DB, giftCardVault string) (*intentModel, error) {
560578
res := []*intentModel{}
561579

562-
query := `SELECT id, intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, relationship_to, tip_platform, tipped_username, phone_number, state, created_at
580+
query := `SELECT id, intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, is_chat, relationship_to, tip_platform, tipped_username, chat_id, phone_number, state, created_at
563581
FROM ` + intentTableName + `
564582
WHERE destination = $1 and intent_type = $2 AND state != $3 AND is_remote_send IS TRUE
565583
LIMIT 2
@@ -591,7 +609,7 @@ func dbGetOriginalGiftCardIssuedIntent(ctx context.Context, db *sqlx.DB, giftCar
591609
func dbGetGiftCardClaimedIntent(ctx context.Context, db *sqlx.DB, giftCardVault string) (*intentModel, error) {
592610
res := []*intentModel{}
593611

594-
query := `SELECT id, intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, relationship_to, tip_platform, tipped_username, phone_number, state, created_at
612+
query := `SELECT id, intent_id, intent_type, owner, source, destination_owner, destination, quantity, treasury_pool, recent_root, exchange_currency, exchange_rate, native_amount, usd_market_value, is_withdraw, is_deposit, is_remote_send, is_returned, is_issuer_voiding_gift_card, is_micro_payment, is_tip, is_chat, relationship_to, tip_platform, tipped_username, chat_id, phone_number, state, created_at
595613
FROM ` + intentTableName + `
596614
WHERE source = $1 and intent_type = $2 AND state != $3 AND is_remote_send IS TRUE
597615
LIMIT 2

pkg/code/data/intent/postgres/store_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ const (
4747
is_issuer_voiding_gift_card BOOL NOT NULL,
4848
is_micro_payment BOOL NOT NULL,
4949
is_tip BOOL NOT NULL,
50+
is_chat BOOL NOT NULL,
5051
5152
relationship_to TEXT NULL,
5253
5354
tip_platform INTEGER NULL,
5455
tipped_username TEXT NULL,
5556
56-
phone_number text NULL,
57+
chat_id TEXT NULL,
58+
phone_number TEXT NULL,
5759
5860
state integer NOT NULL,
5961

pkg/code/data/intent/tests/tests.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func RunTests(t *testing.T, s intent.Store, teardown func()) {
3737
testGetLatestSaveRecentRootIntentForTreasury,
3838
testGetOriginalGiftCardIssuedIntent,
3939
testGetGiftCardClaimedIntent,
40+
testChatPayment,
4041
} {
4142
tf(t, s)
4243
teardown()
@@ -1011,3 +1012,54 @@ func testGetGiftCardClaimedIntent(t *testing.T, s intent.Store) {
10111012
assert.Equal(t, "i9", actual.IntentId)
10121013
})
10131014
}
1015+
1016+
func testChatPayment(t *testing.T, s intent.Store) {
1017+
t.Run("testChatPayment", func(t *testing.T) {
1018+
record := &intent.Record{
1019+
IntentId: "i1",
1020+
IntentType: intent.SendPrivatePayment,
1021+
InitiatorOwnerAccount: "init1",
1022+
SendPrivatePaymentMetadata: &intent.SendPrivatePaymentMetadata{
1023+
DestinationOwnerAccount: "do",
1024+
DestinationTokenAccount: "dt",
1025+
Quantity: 1,
1026+
ExchangeCurrency: "USD",
1027+
ExchangeRate: 1,
1028+
NativeAmount: 1,
1029+
UsdMarketValue: 1,
1030+
IsChat: true,
1031+
ChatId: "chatId",
1032+
},
1033+
}
1034+
require.NoError(t, s.Save(context.Background(), record))
1035+
1036+
saved, err := s.Get(context.Background(), record.IntentId)
1037+
require.NoError(t, err)
1038+
require.Equal(t, record, saved)
1039+
})
1040+
1041+
t.Run("testChatPayment invalid", func(t *testing.T) {
1042+
base := &intent.Record{
1043+
IntentId: "i1",
1044+
IntentType: intent.SendPrivatePayment,
1045+
InitiatorOwnerAccount: "init1",
1046+
SendPrivatePaymentMetadata: &intent.SendPrivatePaymentMetadata{
1047+
DestinationOwnerAccount: "do",
1048+
DestinationTokenAccount: "dt",
1049+
Quantity: 1,
1050+
ExchangeCurrency: "USD",
1051+
ExchangeRate: 1,
1052+
NativeAmount: 1,
1053+
UsdMarketValue: 1,
1054+
},
1055+
}
1056+
1057+
r := base.Clone()
1058+
r.SendPrivatePaymentMetadata.IsChat = true
1059+
require.Error(t, s.Save(context.Background(), &r))
1060+
1061+
r = base.Clone()
1062+
r.SendPrivatePaymentMetadata.ChatId = "chatId"
1063+
require.Error(t, s.Save(context.Background(), &r))
1064+
})
1065+
}

pkg/code/push/notifications.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,15 +320,15 @@ func SendChatMessagePushNotification(
320320
for _, content := range chatMessage.Content {
321321
var contentToPush *chatpb.Content
322322
switch typedContent := content.Type.(type) {
323-
case *chatpb.Content_Localized:
324-
localizedPushBody, err := localization.Localize(locale, typedContent.Localized.KeyOrText)
323+
case *chatpb.Content_ServerLocalized:
324+
localizedPushBody, err := localization.Localize(locale, typedContent.ServerLocalized.KeyOrText)
325325
if err != nil {
326326
continue
327327
}
328328

329329
contentToPush = &chatpb.Content{
330-
Type: &chatpb.Content_Localized{
331-
Localized: &chatpb.LocalizedContent{
330+
Type: &chatpb.Content_ServerLocalized{
331+
ServerLocalized: &chatpb.ServerLocalizedContent{
332332
KeyOrText: localizedPushBody,
333333
},
334334
},
@@ -358,8 +358,8 @@ func SendChatMessagePushNotification(
358358
}
359359

360360
contentToPush = &chatpb.Content{
361-
Type: &chatpb.Content_Localized{
362-
Localized: &chatpb.LocalizedContent{
361+
Type: &chatpb.Content_ServerLocalized{
362+
ServerLocalized: &chatpb.ServerLocalizedContent{
363363
KeyOrText: localizedPushBody,
364364
},
365365
},

0 commit comments

Comments
 (0)