From d1b39ba3e2459d142f44fce51e6e4fb5aa5eb3e6 Mon Sep 17 00:00:00 2001 From: Sam Peters Date: Thu, 29 Feb 2024 14:48:23 -0600 Subject: [PATCH] chore: use correct proto --- history/src/services/notifications/index.ts | 8 +- .../notifications/price-changed-event.ts | 50 +- .../notifications/proto/notifications.proto | 35 + .../notifications/proto/notifications_pb.d.ts | 116 +++ .../notifications/proto/notifications_pb.js | 882 +++++++++++++++++- .../services/notifications/index.spec.ts | 13 +- 6 files changed, 1032 insertions(+), 72 deletions(-) diff --git a/history/src/services/notifications/index.ts b/history/src/services/notifications/index.ts index 3e14a27..6d464c9 100644 --- a/history/src/services/notifications/index.ts +++ b/history/src/services/notifications/index.ts @@ -19,16 +19,12 @@ export const NotificationsService = (): INotificationsService => { const priceChanged = async ( args: PriceChangedArgs, ): Promise => { - const priceChangedEvent = createPriceChangedEvent(args) - try { const req = new HandleNotificationEventRequest() const event = new NotificationEvent() - - // TODO: Create price changed event and configure it - + const priceChangedEvent = createPriceChangedEvent(args) + event.setPrice(priceChangedEvent) req.setEvent(event) - await grpcClient.handleNotificationEvent(req) } catch (err) { if (err instanceof Error) { diff --git a/history/src/services/notifications/price-changed-event.ts b/history/src/services/notifications/price-changed-event.ts index 6666534..4c8c51f 100644 --- a/history/src/services/notifications/price-changed-event.ts +++ b/history/src/services/notifications/price-changed-event.ts @@ -1,40 +1,28 @@ -const PriceDirection = { - Increase: "Increase", - Decrease: "Decrease", -} as const - -type PriceDirection = (typeof PriceDirection)[keyof typeof PriceDirection] - -type PriceChangedEvent = { - currentPriceInUsd: string - priceChangeDirection: PriceDirection - priceChangeInBips: string - timeRange: PriceRange - timestamp: number -} +import { Money, PriceChangeDirection, PriceChanged } from "./proto/notifications_pb" export const createPriceChangedEvent = ({ - range, initialPrice, finalPrice, -}: PriceChangedArgs): PriceChangedEvent => { - const priceChange = calculatePriceChangeBips(initialPrice.price, finalPrice.price) +}: PriceChangedArgs) => { + const priceChange = calculatePriceChangePercentage(initialPrice.price, finalPrice.price) - return { - currentPriceInUsd: finalPrice.price.toFixed(2), - priceChangeDirection: priceChange.changeDirection, - priceChangeInBips: priceChange.bipAmount, - timeRange: range, - timestamp: finalPrice.timestamp, - } + const priceOfOneBitcoin = new Money() + priceOfOneBitcoin.setMinorUnits(usdMajorUnitToMinorUnit(finalPrice.price)) + priceOfOneBitcoin.setCurrencyCode("USD") + + const priceChangedEvent = new PriceChanged() + priceChangedEvent.setPriceOfOneBitcoin(priceOfOneBitcoin) + priceChangedEvent.setDirection(priceChange.direction) + priceChangedEvent.setPriceChangePercentage(priceChange.percentage) + return priceChangedEvent } -const calculatePriceChangeBips = (initialPrice: Price, finalPrice: Price) => { - const bipAmount = Math.round( - ((finalPrice - initialPrice) / initialPrice) * 10000, - ).toString() +const usdMajorUnitToMinorUnit = (usd: number) => usd * 100 + +const calculatePriceChangePercentage = (initialPrice: Price, finalPrice: Price) => { + const percentage = ((finalPrice - initialPrice) / initialPrice) * 100 - const changeDirection = - finalPrice > initialPrice ? PriceDirection.Increase : PriceDirection.Decrease - return { bipAmount, changeDirection } + const direction = + finalPrice > initialPrice ? PriceChangeDirection.UP : PriceChangeDirection.DOWN + return { percentage, direction } } diff --git a/history/src/services/notifications/proto/notifications.proto b/history/src/services/notifications/proto/notifications.proto index 0271f2e..0c8aff0 100644 --- a/history/src/services/notifications/proto/notifications.proto +++ b/history/src/services/notifications/proto/notifications.proto @@ -151,6 +151,8 @@ message NotificationEvent { IdentityVerificationApproved identity_verification_approved = 3; IdentityVerificationDeclined identity_verification_declined = 4; IdentityVerificationReviewStarted identity_verification_review_started = 5; + TransactionInfo transaction = 6; + PriceChanged price = 7; } } @@ -199,3 +201,36 @@ message IdentityVerificationDeclined { message IdentityVerificationReviewStarted { string user_id = 1; } + +message TransactionInfo { + string user_id = 1; + TransactionType type = 2; + Money settlement_amount = 3; + optional Money display_amount = 4; +} + +enum TransactionType { + INTRA_LEDGER_RECEIPT = 0; + INTRA_LEDGER_PAYMENT= 1; + ONCHAIN_RECEIPT = 2; + ONCHAIN_RECEIPT_PENDING = 3; + ONCHAIN_PAYMENT = 4; + LIGHTNING_RECEIPT = 5; + LIGHTNING_PAYMENT = 6; +} + +message Money { + string currency_code = 1; + uint64 minor_units = 2; +} + +enum PriceChangeDirection { + UP = 0; + DOWN = 1; +} + +message PriceChanged { + Money price_of_one_bitcoin = 1; + PriceChangeDirection direction = 2; + double price_change_percentage = 3; +} diff --git a/history/src/services/notifications/proto/notifications_pb.d.ts b/history/src/services/notifications/proto/notifications_pb.d.ts index 823dcf3..46ee23d 100644 --- a/history/src/services/notifications/proto/notifications_pb.d.ts +++ b/history/src/services/notifications/proto/notifications_pb.d.ts @@ -630,6 +630,16 @@ export class NotificationEvent extends jspb.Message { getIdentityVerificationReviewStarted(): IdentityVerificationReviewStarted | undefined; setIdentityVerificationReviewStarted(value?: IdentityVerificationReviewStarted): NotificationEvent; + hasTransaction(): boolean; + clearTransaction(): void; + getTransaction(): TransactionInfo | undefined; + setTransaction(value?: TransactionInfo): NotificationEvent; + + hasPrice(): boolean; + clearPrice(): void; + getPrice(): PriceChanged | undefined; + setPrice(value?: PriceChanged): NotificationEvent; + getDataCase(): NotificationEvent.DataCase; serializeBinary(): Uint8Array; @@ -649,6 +659,8 @@ export namespace NotificationEvent { identityVerificationApproved?: IdentityVerificationApproved.AsObject, identityVerificationDeclined?: IdentityVerificationDeclined.AsObject, identityVerificationReviewStarted?: IdentityVerificationReviewStarted.AsObject, + transaction?: TransactionInfo.AsObject, + price?: PriceChanged.AsObject, } export enum DataCase { @@ -658,6 +670,8 @@ export namespace NotificationEvent { IDENTITY_VERIFICATION_APPROVED = 3, IDENTITY_VERIFICATION_DECLINED = 4, IDENTITY_VERIFICATION_REVIEW_STARTED = 5, + TRANSACTION = 6, + PRICE = 7, } } @@ -783,6 +797,93 @@ export namespace IdentityVerificationReviewStarted { } } +export class TransactionInfo extends jspb.Message { + getUserId(): string; + setUserId(value: string): TransactionInfo; + getType(): TransactionType; + setType(value: TransactionType): TransactionInfo; + + hasSettlementAmount(): boolean; + clearSettlementAmount(): void; + getSettlementAmount(): Money | undefined; + setSettlementAmount(value?: Money): TransactionInfo; + + hasDisplayAmount(): boolean; + clearDisplayAmount(): void; + getDisplayAmount(): Money | undefined; + setDisplayAmount(value?: Money): TransactionInfo; + + serializeBinary(): Uint8Array; + toObject(includeInstance?: boolean): TransactionInfo.AsObject; + static toObject(includeInstance: boolean, msg: TransactionInfo): TransactionInfo.AsObject; + static extensions: {[key: number]: jspb.ExtensionFieldInfo}; + static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; + static serializeBinaryToWriter(message: TransactionInfo, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): TransactionInfo; + static deserializeBinaryFromReader(message: TransactionInfo, reader: jspb.BinaryReader): TransactionInfo; +} + +export namespace TransactionInfo { + export type AsObject = { + userId: string, + type: TransactionType, + settlementAmount?: Money.AsObject, + displayAmount?: Money.AsObject, + } +} + +export class Money extends jspb.Message { + getCurrencyCode(): string; + setCurrencyCode(value: string): Money; + getMinorUnits(): number; + setMinorUnits(value: number): Money; + + serializeBinary(): Uint8Array; + toObject(includeInstance?: boolean): Money.AsObject; + static toObject(includeInstance: boolean, msg: Money): Money.AsObject; + static extensions: {[key: number]: jspb.ExtensionFieldInfo}; + static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; + static serializeBinaryToWriter(message: Money, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): Money; + static deserializeBinaryFromReader(message: Money, reader: jspb.BinaryReader): Money; +} + +export namespace Money { + export type AsObject = { + currencyCode: string, + minorUnits: number, + } +} + +export class PriceChanged extends jspb.Message { + + hasPriceOfOneBitcoin(): boolean; + clearPriceOfOneBitcoin(): void; + getPriceOfOneBitcoin(): Money | undefined; + setPriceOfOneBitcoin(value?: Money): PriceChanged; + getDirection(): PriceChangeDirection; + setDirection(value: PriceChangeDirection): PriceChanged; + getPriceChangePercentage(): number; + setPriceChangePercentage(value: number): PriceChanged; + + serializeBinary(): Uint8Array; + toObject(includeInstance?: boolean): PriceChanged.AsObject; + static toObject(includeInstance: boolean, msg: PriceChanged): PriceChanged.AsObject; + static extensions: {[key: number]: jspb.ExtensionFieldInfo}; + static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; + static serializeBinaryToWriter(message: PriceChanged, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): PriceChanged; + static deserializeBinaryFromReader(message: PriceChanged, reader: jspb.BinaryReader): PriceChanged; +} + +export namespace PriceChanged { + export type AsObject = { + priceOfOneBitcoin?: Money.AsObject, + direction: PriceChangeDirection, + priceChangePercentage: number, + } +} + export enum NotificationChannel { PUSH = 0, } @@ -812,3 +913,18 @@ export enum DeclinedReason { DOCUMENTS_DO_NOT_MATCH = 4, OTHER = 5, } + +export enum TransactionType { + INTRA_LEDGER_RECEIPT = 0, + INTRA_LEDGER_PAYMENT = 1, + ONCHAIN_RECEIPT = 2, + ONCHAIN_RECEIPT_PENDING = 3, + ONCHAIN_PAYMENT = 4, + LIGHTNING_RECEIPT = 5, + LIGHTNING_PAYMENT = 6, +} + +export enum PriceChangeDirection { + UP = 0, + DOWN = 1, +} diff --git a/history/src/services/notifications/proto/notifications_pb.js b/history/src/services/notifications/proto/notifications_pb.js index 5e89341..2e8e0e2 100644 --- a/history/src/services/notifications/proto/notifications_pb.js +++ b/history/src/services/notifications/proto/notifications_pb.js @@ -46,17 +46,22 @@ goog.exportSymbol('proto.services.notifications.v1.HandleNotificationEventRespon goog.exportSymbol('proto.services.notifications.v1.IdentityVerificationApproved', null, global); goog.exportSymbol('proto.services.notifications.v1.IdentityVerificationDeclined', null, global); goog.exportSymbol('proto.services.notifications.v1.IdentityVerificationReviewStarted', null, global); +goog.exportSymbol('proto.services.notifications.v1.Money', null, global); goog.exportSymbol('proto.services.notifications.v1.NotificationCategory', null, global); goog.exportSymbol('proto.services.notifications.v1.NotificationChannel', null, global); goog.exportSymbol('proto.services.notifications.v1.NotificationEvent', null, global); goog.exportSymbol('proto.services.notifications.v1.NotificationEvent.DataCase', null, global); goog.exportSymbol('proto.services.notifications.v1.NotificationSettings', null, global); +goog.exportSymbol('proto.services.notifications.v1.PriceChangeDirection', null, global); +goog.exportSymbol('proto.services.notifications.v1.PriceChanged', null, global); goog.exportSymbol('proto.services.notifications.v1.RemoveEmailAddressRequest', null, global); goog.exportSymbol('proto.services.notifications.v1.RemoveEmailAddressResponse', null, global); goog.exportSymbol('proto.services.notifications.v1.RemovePushDeviceTokenRequest', null, global); goog.exportSymbol('proto.services.notifications.v1.RemovePushDeviceTokenResponse', null, global); goog.exportSymbol('proto.services.notifications.v1.ShouldSendNotificationRequest', null, global); goog.exportSymbol('proto.services.notifications.v1.ShouldSendNotificationResponse', null, global); +goog.exportSymbol('proto.services.notifications.v1.TransactionInfo', null, global); +goog.exportSymbol('proto.services.notifications.v1.TransactionType', null, global); goog.exportSymbol('proto.services.notifications.v1.UpdateEmailAddressRequest', null, global); goog.exportSymbol('proto.services.notifications.v1.UpdateEmailAddressResponse', null, global); goog.exportSymbol('proto.services.notifications.v1.UpdateUserLocaleRequest', null, global); @@ -733,6 +738,69 @@ if (goog.DEBUG && !COMPILED) { */ proto.services.notifications.v1.IdentityVerificationReviewStarted.displayName = 'proto.services.notifications.v1.IdentityVerificationReviewStarted'; } +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.services.notifications.v1.TransactionInfo = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.services.notifications.v1.TransactionInfo, jspb.Message); +if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ + proto.services.notifications.v1.TransactionInfo.displayName = 'proto.services.notifications.v1.TransactionInfo'; +} +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.services.notifications.v1.Money = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.services.notifications.v1.Money, jspb.Message); +if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ + proto.services.notifications.v1.Money.displayName = 'proto.services.notifications.v1.Money'; +} +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.services.notifications.v1.PriceChanged = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.services.notifications.v1.PriceChanged, jspb.Message); +if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ + proto.services.notifications.v1.PriceChanged.displayName = 'proto.services.notifications.v1.PriceChanged'; +} @@ -4797,7 +4865,7 @@ proto.services.notifications.v1.HandleNotificationEventResponse.serializeBinaryT * @private {!Array>} * @const */ -proto.services.notifications.v1.NotificationEvent.oneofGroups_ = [[1,2,3,4,5]]; +proto.services.notifications.v1.NotificationEvent.oneofGroups_ = [[1,2,3,4,5,6,7]]; /** * @enum {number} @@ -4808,7 +4876,9 @@ proto.services.notifications.v1.NotificationEvent.DataCase = { CIRCLE_THRESHOLD_REACHED: 2, IDENTITY_VERIFICATION_APPROVED: 3, IDENTITY_VERIFICATION_DECLINED: 4, - IDENTITY_VERIFICATION_REVIEW_STARTED: 5 + IDENTITY_VERIFICATION_REVIEW_STARTED: 5, + TRANSACTION: 6, + PRICE: 7 }; /** @@ -4853,7 +4923,9 @@ proto.services.notifications.v1.NotificationEvent.toObject = function(includeIns circleThresholdReached: (f = msg.getCircleThresholdReached()) && proto.services.notifications.v1.CircleThresholdReached.toObject(includeInstance, f), identityVerificationApproved: (f = msg.getIdentityVerificationApproved()) && proto.services.notifications.v1.IdentityVerificationApproved.toObject(includeInstance, f), identityVerificationDeclined: (f = msg.getIdentityVerificationDeclined()) && proto.services.notifications.v1.IdentityVerificationDeclined.toObject(includeInstance, f), - identityVerificationReviewStarted: (f = msg.getIdentityVerificationReviewStarted()) && proto.services.notifications.v1.IdentityVerificationReviewStarted.toObject(includeInstance, f) + identityVerificationReviewStarted: (f = msg.getIdentityVerificationReviewStarted()) && proto.services.notifications.v1.IdentityVerificationReviewStarted.toObject(includeInstance, f), + transaction: (f = msg.getTransaction()) && proto.services.notifications.v1.TransactionInfo.toObject(includeInstance, f), + price: (f = msg.getPrice()) && proto.services.notifications.v1.PriceChanged.toObject(includeInstance, f) }; if (includeInstance) { @@ -4915,6 +4987,16 @@ proto.services.notifications.v1.NotificationEvent.deserializeBinaryFromReader = reader.readMessage(value,proto.services.notifications.v1.IdentityVerificationReviewStarted.deserializeBinaryFromReader); msg.setIdentityVerificationReviewStarted(value); break; + case 6: + var value = new proto.services.notifications.v1.TransactionInfo; + reader.readMessage(value,proto.services.notifications.v1.TransactionInfo.deserializeBinaryFromReader); + msg.setTransaction(value); + break; + case 7: + var value = new proto.services.notifications.v1.PriceChanged; + reader.readMessage(value,proto.services.notifications.v1.PriceChanged.deserializeBinaryFromReader); + msg.setPrice(value); + break; default: reader.skipField(); break; @@ -4984,6 +5066,22 @@ proto.services.notifications.v1.NotificationEvent.serializeBinaryToWriter = func proto.services.notifications.v1.IdentityVerificationReviewStarted.serializeBinaryToWriter ); } + f = message.getTransaction(); + if (f != null) { + writer.writeMessage( + 6, + f, + proto.services.notifications.v1.TransactionInfo.serializeBinaryToWriter + ); + } + f = message.getPrice(); + if (f != null) { + writer.writeMessage( + 7, + f, + proto.services.notifications.v1.PriceChanged.serializeBinaryToWriter + ); + } }; @@ -5172,6 +5270,80 @@ proto.services.notifications.v1.NotificationEvent.prototype.hasIdentityVerificat }; +/** + * optional TransactionInfo transaction = 6; + * @return {?proto.services.notifications.v1.TransactionInfo} + */ +proto.services.notifications.v1.NotificationEvent.prototype.getTransaction = function() { + return /** @type{?proto.services.notifications.v1.TransactionInfo} */ ( + jspb.Message.getWrapperField(this, proto.services.notifications.v1.TransactionInfo, 6)); +}; + + +/** + * @param {?proto.services.notifications.v1.TransactionInfo|undefined} value + * @return {!proto.services.notifications.v1.NotificationEvent} returns this +*/ +proto.services.notifications.v1.NotificationEvent.prototype.setTransaction = function(value) { + return jspb.Message.setOneofWrapperField(this, 6, proto.services.notifications.v1.NotificationEvent.oneofGroups_[0], value); +}; + + +/** + * Clears the message field making it undefined. + * @return {!proto.services.notifications.v1.NotificationEvent} returns this + */ +proto.services.notifications.v1.NotificationEvent.prototype.clearTransaction = function() { + return this.setTransaction(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {boolean} + */ +proto.services.notifications.v1.NotificationEvent.prototype.hasTransaction = function() { + return jspb.Message.getField(this, 6) != null; +}; + + +/** + * optional PriceChanged price = 7; + * @return {?proto.services.notifications.v1.PriceChanged} + */ +proto.services.notifications.v1.NotificationEvent.prototype.getPrice = function() { + return /** @type{?proto.services.notifications.v1.PriceChanged} */ ( + jspb.Message.getWrapperField(this, proto.services.notifications.v1.PriceChanged, 7)); +}; + + +/** + * @param {?proto.services.notifications.v1.PriceChanged|undefined} value + * @return {!proto.services.notifications.v1.NotificationEvent} returns this +*/ +proto.services.notifications.v1.NotificationEvent.prototype.setPrice = function(value) { + return jspb.Message.setOneofWrapperField(this, 7, proto.services.notifications.v1.NotificationEvent.oneofGroups_[0], value); +}; + + +/** + * Clears the message field making it undefined. + * @return {!proto.services.notifications.v1.NotificationEvent} returns this + */ +proto.services.notifications.v1.NotificationEvent.prototype.clearPrice = function() { + return this.setPrice(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {boolean} + */ +proto.services.notifications.v1.NotificationEvent.prototype.hasPrice = function() { + return jspb.Message.getField(this, 7) != null; +}; + + @@ -6032,49 +6204,703 @@ proto.services.notifications.v1.IdentityVerificationReviewStarted.prototype.setU }; + + + +if (jspb.Message.GENERATE_TO_OBJECT) { /** - * @enum {number} + * Creates an object representation of this proto. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * Optional fields that are not set will be set to undefined. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * net/proto2/compiler/js/internal/generator.cc#kKeyword. + * @param {boolean=} opt_includeInstance Deprecated. whether to include the + * JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @return {!Object} */ -proto.services.notifications.v1.NotificationChannel = { - PUSH: 0 +proto.services.notifications.v1.TransactionInfo.prototype.toObject = function(opt_includeInstance) { + return proto.services.notifications.v1.TransactionInfo.toObject(opt_includeInstance, this); }; + /** - * @enum {number} + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Deprecated. Whether to include + * the JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.services.notifications.v1.TransactionInfo} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages */ -proto.services.notifications.v1.NotificationCategory = { - CIRCLES: 0, - PAYMENTS: 1, - BALANCE: 2, - ADMIN_NOTIFICATION: 3 +proto.services.notifications.v1.TransactionInfo.toObject = function(includeInstance, msg) { + var f, obj = { + userId: jspb.Message.getFieldWithDefault(msg, 1, ""), + type: jspb.Message.getFieldWithDefault(msg, 2, 0), + settlementAmount: (f = msg.getSettlementAmount()) && proto.services.notifications.v1.Money.toObject(includeInstance, f), + displayAmount: (f = msg.getDisplayAmount()) && proto.services.notifications.v1.Money.toObject(includeInstance, f) + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; }; +} + /** - * @enum {number} + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.services.notifications.v1.TransactionInfo} */ -proto.services.notifications.v1.CircleType = { - INNER: 0, - OUTER: 1 +proto.services.notifications.v1.TransactionInfo.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.services.notifications.v1.TransactionInfo; + return proto.services.notifications.v1.TransactionInfo.deserializeBinaryFromReader(msg, reader); }; + /** - * @enum {number} + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.services.notifications.v1.TransactionInfo} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.services.notifications.v1.TransactionInfo} */ -proto.services.notifications.v1.CircleTimeFrame = { - MONTH: 0, - ALL_TIME: 1 +proto.services.notifications.v1.TransactionInfo.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = /** @type {string} */ (reader.readString()); + msg.setUserId(value); + break; + case 2: + var value = /** @type {!proto.services.notifications.v1.TransactionType} */ (reader.readEnum()); + msg.setType(value); + break; + case 3: + var value = new proto.services.notifications.v1.Money; + reader.readMessage(value,proto.services.notifications.v1.Money.deserializeBinaryFromReader); + msg.setSettlementAmount(value); + break; + case 4: + var value = new proto.services.notifications.v1.Money; + reader.readMessage(value,proto.services.notifications.v1.Money.deserializeBinaryFromReader); + msg.setDisplayAmount(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; }; + /** - * @enum {number} + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} */ -proto.services.notifications.v1.DeclinedReason = { - DOCUMENTS_NOT_CLEAR: 0, - VERIFICATION_PHOTO_NOT_CLEAR: 1, - DOCUMENTS_NOT_SUPPORTED: 2, - DOCUMENTS_EXPIRED: 3, - DOCUMENTS_DO_NOT_MATCH: 4, - OTHER: 5 +proto.services.notifications.v1.TransactionInfo.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.services.notifications.v1.TransactionInfo.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.services.notifications.v1.TransactionInfo} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.services.notifications.v1.TransactionInfo.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getUserId(); + if (f.length > 0) { + writer.writeString( + 1, + f + ); + } + f = message.getType(); + if (f !== 0.0) { + writer.writeEnum( + 2, + f + ); + } + f = message.getSettlementAmount(); + if (f != null) { + writer.writeMessage( + 3, + f, + proto.services.notifications.v1.Money.serializeBinaryToWriter + ); + } + f = message.getDisplayAmount(); + if (f != null) { + writer.writeMessage( + 4, + f, + proto.services.notifications.v1.Money.serializeBinaryToWriter + ); + } +}; + + +/** + * optional string user_id = 1; + * @return {string} + */ +proto.services.notifications.v1.TransactionInfo.prototype.getUserId = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); +}; + + +/** + * @param {string} value + * @return {!proto.services.notifications.v1.TransactionInfo} returns this + */ +proto.services.notifications.v1.TransactionInfo.prototype.setUserId = function(value) { + return jspb.Message.setProto3StringField(this, 1, value); +}; + + +/** + * optional TransactionType type = 2; + * @return {!proto.services.notifications.v1.TransactionType} + */ +proto.services.notifications.v1.TransactionInfo.prototype.getType = function() { + return /** @type {!proto.services.notifications.v1.TransactionType} */ (jspb.Message.getFieldWithDefault(this, 2, 0)); +}; + + +/** + * @param {!proto.services.notifications.v1.TransactionType} value + * @return {!proto.services.notifications.v1.TransactionInfo} returns this + */ +proto.services.notifications.v1.TransactionInfo.prototype.setType = function(value) { + return jspb.Message.setProto3EnumField(this, 2, value); +}; + + +/** + * optional Money settlement_amount = 3; + * @return {?proto.services.notifications.v1.Money} + */ +proto.services.notifications.v1.TransactionInfo.prototype.getSettlementAmount = function() { + return /** @type{?proto.services.notifications.v1.Money} */ ( + jspb.Message.getWrapperField(this, proto.services.notifications.v1.Money, 3)); +}; + + +/** + * @param {?proto.services.notifications.v1.Money|undefined} value + * @return {!proto.services.notifications.v1.TransactionInfo} returns this +*/ +proto.services.notifications.v1.TransactionInfo.prototype.setSettlementAmount = function(value) { + return jspb.Message.setWrapperField(this, 3, value); +}; + + +/** + * Clears the message field making it undefined. + * @return {!proto.services.notifications.v1.TransactionInfo} returns this + */ +proto.services.notifications.v1.TransactionInfo.prototype.clearSettlementAmount = function() { + return this.setSettlementAmount(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {boolean} + */ +proto.services.notifications.v1.TransactionInfo.prototype.hasSettlementAmount = function() { + return jspb.Message.getField(this, 3) != null; +}; + + +/** + * optional Money display_amount = 4; + * @return {?proto.services.notifications.v1.Money} + */ +proto.services.notifications.v1.TransactionInfo.prototype.getDisplayAmount = function() { + return /** @type{?proto.services.notifications.v1.Money} */ ( + jspb.Message.getWrapperField(this, proto.services.notifications.v1.Money, 4)); +}; + + +/** + * @param {?proto.services.notifications.v1.Money|undefined} value + * @return {!proto.services.notifications.v1.TransactionInfo} returns this +*/ +proto.services.notifications.v1.TransactionInfo.prototype.setDisplayAmount = function(value) { + return jspb.Message.setWrapperField(this, 4, value); +}; + + +/** + * Clears the message field making it undefined. + * @return {!proto.services.notifications.v1.TransactionInfo} returns this + */ +proto.services.notifications.v1.TransactionInfo.prototype.clearDisplayAmount = function() { + return this.setDisplayAmount(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {boolean} + */ +proto.services.notifications.v1.TransactionInfo.prototype.hasDisplayAmount = function() { + return jspb.Message.getField(this, 4) != null; +}; + + + + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * Optional fields that are not set will be set to undefined. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * net/proto2/compiler/js/internal/generator.cc#kKeyword. + * @param {boolean=} opt_includeInstance Deprecated. whether to include the + * JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @return {!Object} + */ +proto.services.notifications.v1.Money.prototype.toObject = function(opt_includeInstance) { + return proto.services.notifications.v1.Money.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Deprecated. Whether to include + * the JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.services.notifications.v1.Money} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.services.notifications.v1.Money.toObject = function(includeInstance, msg) { + var f, obj = { + currencyCode: jspb.Message.getFieldWithDefault(msg, 1, ""), + minorUnits: jspb.Message.getFieldWithDefault(msg, 2, 0) + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.services.notifications.v1.Money} + */ +proto.services.notifications.v1.Money.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.services.notifications.v1.Money; + return proto.services.notifications.v1.Money.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.services.notifications.v1.Money} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.services.notifications.v1.Money} + */ +proto.services.notifications.v1.Money.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = /** @type {string} */ (reader.readString()); + msg.setCurrencyCode(value); + break; + case 2: + var value = /** @type {number} */ (reader.readUint64()); + msg.setMinorUnits(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.services.notifications.v1.Money.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.services.notifications.v1.Money.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.services.notifications.v1.Money} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.services.notifications.v1.Money.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getCurrencyCode(); + if (f.length > 0) { + writer.writeString( + 1, + f + ); + } + f = message.getMinorUnits(); + if (f !== 0) { + writer.writeUint64( + 2, + f + ); + } +}; + + +/** + * optional string currency_code = 1; + * @return {string} + */ +proto.services.notifications.v1.Money.prototype.getCurrencyCode = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); +}; + + +/** + * @param {string} value + * @return {!proto.services.notifications.v1.Money} returns this + */ +proto.services.notifications.v1.Money.prototype.setCurrencyCode = function(value) { + return jspb.Message.setProto3StringField(this, 1, value); +}; + + +/** + * optional uint64 minor_units = 2; + * @return {number} + */ +proto.services.notifications.v1.Money.prototype.getMinorUnits = function() { + return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 2, 0)); +}; + + +/** + * @param {number} value + * @return {!proto.services.notifications.v1.Money} returns this + */ +proto.services.notifications.v1.Money.prototype.setMinorUnits = function(value) { + return jspb.Message.setProto3IntField(this, 2, value); +}; + + + + + +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * Optional fields that are not set will be set to undefined. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * net/proto2/compiler/js/internal/generator.cc#kKeyword. + * @param {boolean=} opt_includeInstance Deprecated. whether to include the + * JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @return {!Object} + */ +proto.services.notifications.v1.PriceChanged.prototype.toObject = function(opt_includeInstance) { + return proto.services.notifications.v1.PriceChanged.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Deprecated. Whether to include + * the JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.services.notifications.v1.PriceChanged} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.services.notifications.v1.PriceChanged.toObject = function(includeInstance, msg) { + var f, obj = { + priceOfOneBitcoin: (f = msg.getPriceOfOneBitcoin()) && proto.services.notifications.v1.Money.toObject(includeInstance, f), + direction: jspb.Message.getFieldWithDefault(msg, 2, 0), + priceChangePercentage: jspb.Message.getFloatingPointFieldWithDefault(msg, 3, 0.0) + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.services.notifications.v1.PriceChanged} + */ +proto.services.notifications.v1.PriceChanged.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.services.notifications.v1.PriceChanged; + return proto.services.notifications.v1.PriceChanged.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.services.notifications.v1.PriceChanged} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.services.notifications.v1.PriceChanged} + */ +proto.services.notifications.v1.PriceChanged.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = new proto.services.notifications.v1.Money; + reader.readMessage(value,proto.services.notifications.v1.Money.deserializeBinaryFromReader); + msg.setPriceOfOneBitcoin(value); + break; + case 2: + var value = /** @type {!proto.services.notifications.v1.PriceChangeDirection} */ (reader.readEnum()); + msg.setDirection(value); + break; + case 3: + var value = /** @type {number} */ (reader.readDouble()); + msg.setPriceChangePercentage(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.services.notifications.v1.PriceChanged.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.services.notifications.v1.PriceChanged.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.services.notifications.v1.PriceChanged} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.services.notifications.v1.PriceChanged.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getPriceOfOneBitcoin(); + if (f != null) { + writer.writeMessage( + 1, + f, + proto.services.notifications.v1.Money.serializeBinaryToWriter + ); + } + f = message.getDirection(); + if (f !== 0.0) { + writer.writeEnum( + 2, + f + ); + } + f = message.getPriceChangePercentage(); + if (f !== 0.0) { + writer.writeDouble( + 3, + f + ); + } +}; + + +/** + * optional Money price_of_one_bitcoin = 1; + * @return {?proto.services.notifications.v1.Money} + */ +proto.services.notifications.v1.PriceChanged.prototype.getPriceOfOneBitcoin = function() { + return /** @type{?proto.services.notifications.v1.Money} */ ( + jspb.Message.getWrapperField(this, proto.services.notifications.v1.Money, 1)); +}; + + +/** + * @param {?proto.services.notifications.v1.Money|undefined} value + * @return {!proto.services.notifications.v1.PriceChanged} returns this +*/ +proto.services.notifications.v1.PriceChanged.prototype.setPriceOfOneBitcoin = function(value) { + return jspb.Message.setWrapperField(this, 1, value); +}; + + +/** + * Clears the message field making it undefined. + * @return {!proto.services.notifications.v1.PriceChanged} returns this + */ +proto.services.notifications.v1.PriceChanged.prototype.clearPriceOfOneBitcoin = function() { + return this.setPriceOfOneBitcoin(undefined); +}; + + +/** + * Returns whether this field is set. + * @return {boolean} + */ +proto.services.notifications.v1.PriceChanged.prototype.hasPriceOfOneBitcoin = function() { + return jspb.Message.getField(this, 1) != null; +}; + + +/** + * optional PriceChangeDirection direction = 2; + * @return {!proto.services.notifications.v1.PriceChangeDirection} + */ +proto.services.notifications.v1.PriceChanged.prototype.getDirection = function() { + return /** @type {!proto.services.notifications.v1.PriceChangeDirection} */ (jspb.Message.getFieldWithDefault(this, 2, 0)); +}; + + +/** + * @param {!proto.services.notifications.v1.PriceChangeDirection} value + * @return {!proto.services.notifications.v1.PriceChanged} returns this + */ +proto.services.notifications.v1.PriceChanged.prototype.setDirection = function(value) { + return jspb.Message.setProto3EnumField(this, 2, value); +}; + + +/** + * optional double price_change_percentage = 3; + * @return {number} + */ +proto.services.notifications.v1.PriceChanged.prototype.getPriceChangePercentage = function() { + return /** @type {number} */ (jspb.Message.getFloatingPointFieldWithDefault(this, 3, 0.0)); +}; + + +/** + * @param {number} value + * @return {!proto.services.notifications.v1.PriceChanged} returns this + */ +proto.services.notifications.v1.PriceChanged.prototype.setPriceChangePercentage = function(value) { + return jspb.Message.setProto3FloatField(this, 3, value); +}; + + +/** + * @enum {number} + */ +proto.services.notifications.v1.NotificationChannel = { + PUSH: 0 +}; + +/** + * @enum {number} + */ +proto.services.notifications.v1.NotificationCategory = { + CIRCLES: 0, + PAYMENTS: 1, + BALANCE: 2, + ADMIN_NOTIFICATION: 3 +}; + +/** + * @enum {number} + */ +proto.services.notifications.v1.CircleType = { + INNER: 0, + OUTER: 1 +}; + +/** + * @enum {number} + */ +proto.services.notifications.v1.CircleTimeFrame = { + MONTH: 0, + ALL_TIME: 1 +}; + +/** + * @enum {number} + */ +proto.services.notifications.v1.DeclinedReason = { + DOCUMENTS_NOT_CLEAR: 0, + VERIFICATION_PHOTO_NOT_CLEAR: 1, + DOCUMENTS_NOT_SUPPORTED: 2, + DOCUMENTS_EXPIRED: 3, + DOCUMENTS_DO_NOT_MATCH: 4, + OTHER: 5 +}; + +/** + * @enum {number} + */ +proto.services.notifications.v1.TransactionType = { + INTRA_LEDGER_RECEIPT: 0, + INTRA_LEDGER_PAYMENT: 1, + ONCHAIN_RECEIPT: 2, + ONCHAIN_RECEIPT_PENDING: 3, + ONCHAIN_PAYMENT: 4, + LIGHTNING_RECEIPT: 5, + LIGHTNING_PAYMENT: 6 +}; + +/** + * @enum {number} + */ +proto.services.notifications.v1.PriceChangeDirection = { + UP: 0, + DOWN: 1 }; goog.object.extend(exports, proto.services.notifications.v1); diff --git a/history/test/unit/utils/services/notifications/index.spec.ts b/history/test/unit/utils/services/notifications/index.spec.ts index adc1947..84aa667 100644 --- a/history/test/unit/utils/services/notifications/index.spec.ts +++ b/history/test/unit/utils/services/notifications/index.spec.ts @@ -1,5 +1,6 @@ import { PriceRange } from "@domain/price" import { createPriceChangedEvent } from "@services/notifications/price-changed-event" +import { PriceChangeDirection } from "@services/notifications/proto/notifications_pb" describe("createPriceChangedEvent", () => { it("should create a price changed event", () => { @@ -7,12 +8,10 @@ describe("createPriceChangedEvent", () => { const initialPrice = { price: 50, timestamp: 0 } as Tick const finalPrice = { price: 75, timestamp: 100 } as Tick const event = createPriceChangedEvent({ range, initialPrice, finalPrice }) - expect(event).toEqual({ - currentPriceInUsd: "75.00", - priceChangeDirection: "Increase", - priceChangeInBips: "5000", - timeRange: range, - timestamp: 100, - }) + + expect(event.getDirection()).toEqual(PriceChangeDirection.UP) + expect(event.getPriceChangePercentage()).toEqual(50) + expect(event.getPriceOfOneBitcoin()?.getMinorUnits()).toEqual(7500) + expect(event.getPriceOfOneBitcoin()?.getCurrencyCode()).toEqual("USD") }) })