Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix payment balances not called after first run of application #2808

Merged
merged 2 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,12 @@ bool ConfirmationsImpl::ParseNextTokenRedemptionDateInSecondsFromJSON(
return false;
}

next_token_redemption_date_in_seconds_ =
auto next_token_redemption_date_in_seconds =
std::stoull(next_token_redemption_date_in_seconds_value->GetString());

next_token_redemption_date_in_seconds_ =
Time::MigrateTimestampToDoubleT(next_token_redemption_date_in_seconds);

return true;
}

Expand Down Expand Up @@ -589,8 +592,11 @@ bool ConfirmationsImpl::GetTransactionHistoryFromDictionary(
auto* timestamp_in_seconds_value =
transaction_dictionary->FindKey("timestamp_in_seconds");
if (timestamp_in_seconds_value) {
info.timestamp_in_seconds =
auto timestamp_in_seconds =
std::stoull(timestamp_in_seconds_value->GetString());

info.timestamp_in_seconds =
Time::MigrateTimestampToDoubleT(timestamp_in_seconds);
} else {
// timestamp missing, fallback to default
info.timestamp_in_seconds = Time::NowInSeconds();
Expand Down Expand Up @@ -917,7 +923,7 @@ uint64_t ConfirmationsImpl::GetAdNotificationsReceivedThisMonthForTransactions(

for (const auto& transaction : transactions) {
auto transaction_timestamp =
base::Time::FromDoubleT(transaction.timestamp_in_seconds);
Time::FromDoubleT(transaction.timestamp_in_seconds);

base::Time::Exploded transaction_timestamp_exploded;
transaction_timestamp.LocalExplode(&transaction_timestamp_exploded);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "bat/confirmations/internal/static_values.h"
#include "bat/confirmations/internal/logging.h"
#include "bat/confirmations/internal/confirmations_impl.h"
#include "bat/confirmations/internal/time.h"

#include "base/json/json_reader.h"
#include "base/strings/stringprintf.h"
Expand Down Expand Up @@ -151,7 +152,7 @@ base::Time Payments::CalculateNextPaymentDate(
month++;
} else {
auto next_token_redemption_date =
base::Time::FromDoubleT(next_token_redemption_date_in_seconds);
Time::FromDoubleT(next_token_redemption_date_in_seconds);

base::Time::Exploded next_token_redemption_date_exploded;
next_token_redemption_date.LocalExplode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,37 @@

#include "bat/confirmations/internal/time.h"

#include "base/time/time.h"

namespace confirmations {

uint64_t Time::NowInSeconds() {
auto now = base::Time::Now();
return now.ToDoubleT();
}

uint64_t Time::MigrateTimestampToDoubleT(const uint64_t timestamp_in_seconds) {
if (timestamp_in_seconds < 10000000000) {
// Already migrated as DoubleT will never reach 10000000000 in our lifetime
// and legacy timestamps are above 10000000000
return timestamp_in_seconds;
}

// Migrate date to DoubleT
auto now = base::Time::Now();
auto now_in_seconds = static_cast<uint64_t>((now - base::Time()).InSeconds());

auto delta = timestamp_in_seconds - now_in_seconds;

auto date = now + base::TimeDelta::FromSeconds(delta);
return date.ToDoubleT();
}

base::Time Time::FromDoubleT(const uint64_t timestamp_in_seconds) {
if (timestamp_in_seconds == 0) {
// Workaround for Windows crash when passing 0 to LocalExplode
return base::Time::Now();
}

return base::Time::FromDoubleT(timestamp_in_seconds);
}

} // namespace confirmations
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@

#include <stdint.h>

#include "base/time/time.h"

namespace confirmations {

class Time {
public:
static uint64_t NowInSeconds();
static uint64_t MigrateTimestampToDoubleT(
const uint64_t timestamp_in_seconds);
static base::Time FromDoubleT(
const uint64_t timestamp_in_seconds);
};

} // namespace confirmations
Expand Down