Skip to content

Commit

Permalink
Merge pull request #1062 from brave-intl/master
Browse files Browse the repository at this point in the history
production 2021-12-16_2
  • Loading branch information
husobee committed Dec 17, 2021
2 parents 0196197 + a2cad61 commit 3a2230b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
31 changes: 22 additions & 9 deletions promotion/drain.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,16 @@ func (service *Service) SubmitBatchTransfer(ctx context.Context, batchID *uuid.U
totalJPYTransfer = decimal.Zero
)

var (
totalF64 float64
depositID string
transferID string
)

for _, v := range transfers {
totalF64, _ := v.Total.Float64()
t, _ := v.Total.Float64()
totalF64 += t

totalJPYTransfer = totalJPYTransfer.Add(v.Total.Mul(quote.Rate))

if totalJPYTransfer.GreaterThan(JPYLimit) {
Expand All @@ -347,17 +355,22 @@ func (service *Service) SubmitBatchTransfer(ctx context.Context, batchID *uuid.U
over, quote.Rate, totalJPYTransfer),
"over custodian transfer limit",
new(bitflyerOverTransferLimit))
break
}

withdraws = append(withdraws, bitflyer.WithdrawToDepositIDPayload{
CurrencyCode: "BAT",
Amount: totalF64,
DepositID: *v.DepositID,
TransferID: v.ID.String(),
SourceFrom: "userdrain",
})
depositID = *v.DepositID
transferID = transferID + v.ID.String()
}

// collapse into one transaction, not multiples in a bulk upload

withdraws = append(withdraws, bitflyer.WithdrawToDepositIDPayload{
CurrencyCode: "BAT",
Amount: totalF64,
DepositID: depositID,
TransferID: transferID,
SourceFrom: "userdrain",
})

// create a WithdrawToDepositIDBulkPayload
payload := bitflyer.WithdrawToDepositIDBulkPayload{
Withdrawals: withdraws,
Expand Down
10 changes: 6 additions & 4 deletions promotion/suggestions.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ func (service *Service) GetCredentialRedemptions(ctx context.Context, credential

if issuer, ok = issuers[publicKey]; !ok {
issuer, err = service.Datastore.GetIssuerByPublicKey(publicKey)
if err != nil {
err = errorutils.Wrap(err, "error finding issuer")
if err != nil || issuer == nil {
e := fmt.Errorf("error finding issuer %s: %w", publicKey, err)
err = errorutils.Wrap(e, e.Error())
return
}
}
Expand All @@ -175,8 +176,9 @@ func (service *Service) GetCredentialRedemptions(ctx context.Context, credential

if promotion, ok = promotions[publicKey]; !ok {
promotion, err = service.Datastore.GetPromotion(issuer.PromotionID)
if err != nil {
err = errorutils.Wrap(err, "error finding promotion")
if err != nil || promotion == nil {
e := fmt.Errorf("error finding promotion %s: %w", issuer.PromotionID, err)
err = errorutils.Wrap(e, e.Error())
return
}
promotions[publicKey] = promotion
Expand Down

0 comments on commit 3a2230b

Please sign in to comment.