Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

Commit de727b5

Browse files
authored
Merge pull request #2053 from OpenBazaar/brian.notification-fixes
Check for pre-bigInt notifications pricing
2 parents ce1c135 + b8b71e1 commit de727b5

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

repo/notification.go

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json" //"errors"
66
"fmt"
77
mh "gx/ipfs/QmerPMzPk1mJVowm8KgmoknWa4yCYvvugMPsgWmDNUvDLW/go-multihash"
8+
"math/big"
89
"time"
910
)
1011

@@ -313,7 +314,27 @@ func (n *Notification) UnmarshalJSON(data []byte) error {
313314
case NotifierTypeOrderNewNotification:
314315
var notifier = OrderNotification{}
315316
if err := json.Unmarshal(payload.NotifierData, &notifier); err != nil {
316-
return err
317+
notifierLegacy := OrderNotificationV4{}
318+
if err2 := json.Unmarshal(payload.NotifierData, &notifierLegacy); err2 != nil {
319+
return err2
320+
}
321+
notifier.OrderId = notifierLegacy.OrderId
322+
notifier.BuyerHandle = notifierLegacy.BuyerHandle
323+
notifier.BuyerID = notifierLegacy.BuyerID
324+
notifier.ID = notifierLegacy.ID
325+
notifier.Price = &CurrencyValue{
326+
Amount: new(big.Int).SetUint64(notifierLegacy.Price.Amount),
327+
Currency: CurrencyDefinition{
328+
Code: CurrencyCode(notifierLegacy.Price.CurrencyCode),
329+
Divisibility: uint(notifierLegacy.Price.CoinDivisibility),
330+
},
331+
}
332+
notifier.PriceModifier = notifierLegacy.PriceModifier
333+
notifier.Slug = notifierLegacy.Slug
334+
notifier.Type = notifierLegacy.Type
335+
notifier.ListingType = notifierLegacy.ListingType
336+
notifier.Thumbnail = notifierLegacy.Thumbnail
337+
notifier.Title = notifierLegacy.Title
317338
}
318339
n.NotifierData = notifier
319340
case NotifierTypePaymentNotification:
@@ -413,6 +434,27 @@ type OrderNotification struct {
413434
Type NotificationType `json:"type"`
414435
}
415436

437+
type ListingPrice struct {
438+
Amount uint64 `json:"amount"`
439+
CurrencyCode string `json:"currencyCode"`
440+
PriceModifier float32 `json:"priceModifier"`
441+
CoinDivisibility uint32 `json:"coinDivisibility"`
442+
}
443+
444+
type OrderNotificationV4 struct {
445+
BuyerHandle string `json:"buyerHandle"`
446+
BuyerID string `json:"buyerId"`
447+
ID string `json:"notificationId"`
448+
ListingType string `json:"listingType"`
449+
OrderId string `json:"orderId"`
450+
Price ListingPrice `json:"price"`
451+
PriceModifier float32 `json:"priceModifier"`
452+
Slug string `json:"slug"`
453+
Thumbnail Thumbnail `json:"thumbnail"`
454+
Title string `json:"title"`
455+
Type NotificationType `json:"type"`
456+
}
457+
416458
func (n OrderNotification) Data() ([]byte, error) {
417459
return json.MarshalIndent(notificationWrapper{n}, "", " ")
418460
}

0 commit comments

Comments
 (0)