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

Commit b21b83c

Browse files
committed
Fix bug returning coupon discount code for own node
1 parent cae0bf0 commit b21b83c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

repo/listing.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ func (l *Listing) UpdateCouponsFromDatastore(cdb couponGetter) error {
843843
if err != nil {
844844
return fmt.Errorf("loading datastore coupon: %s", err.Error())
845845
}
846-
for _, c := range coupons {
846+
for i, c := range coupons {
847847
for _, dbc := range dbCoupons {
848848
if c.redemptionHash == dbc.Hash {
849849
// make sure applying code does not shift already-matched hash
@@ -854,12 +854,13 @@ func (l *Listing) UpdateCouponsFromDatastore(cdb couponGetter) error {
854854
if c.redemptionHash != expectedHash.B58String() {
855855
return fmt.Errorf("update coupon code (%s) results in mismatched published hash", dbc.Code)
856856
}
857-
if err := c.SetRedemptionCode(dbc.Code); err != nil {
857+
if err := coupons[i].SetRedemptionCode(dbc.Code); err != nil {
858858
return fmt.Errorf("setting redemption code: %s", err.Error())
859859
}
860860
}
861861
}
862862
}
863+
l.listingProto.Coupons = coupons.GetProtobuf()
863864
return nil
864865
}
865866

@@ -920,11 +921,14 @@ func (cs ListingCoupons) GetProtobuf() []*pb.Listing_Coupon {
920921
cspb[i] = &pb.Listing_Coupon{
921922
Title: c.GetTitle(),
922923
PercentDiscount: c.GetPercentOff(),
923-
BigPriceDiscount: c.GetAmountOff().Amount.String(),
924+
}
925+
if c.GetAmountOff() != nil {
926+
cspb[i].BigPriceDiscount = c.GetAmountOff().Amount.String()
924927
}
925928
if hash, err := c.GetRedemptionHash(); err == nil {
926929
cspb[i].Code = &pb.Listing_Coupon_Hash{Hash: hash}
927-
} else if code, err := c.GetRedemptionCode(); err == nil {
930+
}
931+
if code, err := c.GetRedemptionCode(); err == nil {
928932
cspb[i].Code = &pb.Listing_Coupon_DiscountCode{DiscountCode: code}
929933
}
930934
}

0 commit comments

Comments
 (0)