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 and simplify month in airdrop messages #6123

Merged
merged 4 commits into from
Jul 26, 2024
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
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion backend/canisters/airdrop_bot/impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ serde_json = { workspace = true }
serializer = { path = "../../../libraries/serializer" }
stable_memory = { path = "../../../libraries/stable_memory" }
testing = { path = "../../../libraries/testing" }
time = { workspace = true, features = ["macros", "formatting"] }
tracing = { workspace = true }
types = { path = "../../../libraries/types" }
user_canister_c2c_client = { path = "../../user/c2c_client" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use icrc_ledger_types::icrc1::transfer::{TransferArg, TransferError};
use rand::Rng;
use std::cell::Cell;
use std::time::Duration;
use time::macros::format_description;
megrogan marked this conversation as resolved.
Show resolved Hide resolved
use tracing::{error, trace};
use types::icrc1::{self};
use types::{
BotMessage, CanisterId, ChannelId, CommunityId, CompletedCryptoTransaction, CryptoContent, CryptoTransaction,
Cryptocurrency, MessageContentInitial,
};
use utils::consts::{MEMO_CHIT_FOR_CHAT_AIRDROP, MEMO_CHIT_FOR_CHAT_LOTTERY};
use utils::time::{MonthKey, MONTHS};

use super::execute_airdrop::start_airdrop_timer;

Expand Down Expand Up @@ -186,10 +186,9 @@ async fn handle_main_message_action(action: AirdropMessage) {
};

let Some(month) = read_state(|state| {
state.data.airdrops.current(state.env.now()).and_then(|c| {
let date = time::OffsetDateTime::from_unix_timestamp((c.start / 1000) as i64).unwrap();
let format = format_description!("[month repr:long]");
date.format(format).ok()
state.data.airdrops.current(state.env.now()).map(|c| {
let mk = MonthKey::from_timestamp(c.start).previous();
MONTHS[mk.month() as usize]
})
}) else {
return;
Expand Down
4 changes: 0 additions & 4 deletions backend/canisters/airdrop_bot/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ impl RuntimeState {
cycles_balance: self.env.cycles_balance(),
wasm_version: WASM_VERSION.with_borrow(|v| **v),
git_commit_id: utils::git::git_commit_id().to_string(),
initialized: self.data.initialized,
canister_ids: CanisterIds {
user_index: self.data.user_index_canister_id,
local_user_index: self.data.local_user_index_canister_id,
Expand All @@ -73,7 +72,6 @@ struct Data {
pub airdrops: Airdrops,
pub channels_joined: HashSet<(CommunityId, ChannelId)>,
pub pending_actions_queue: PendingActionsQueue,
pub initialized: bool,
pub rng_seed: [u8; 32],
pub test_mode: bool,
}
Expand All @@ -95,7 +93,6 @@ impl Data {
airdrops: Airdrops::default(),
channels_joined: HashSet::default(),
pending_actions_queue: PendingActionsQueue::default(),
initialized: false,
rng_seed: [0; 32],
test_mode,
}
Expand All @@ -110,7 +107,6 @@ pub struct Metrics {
pub cycles_balance: Cycles,
pub wasm_version: BuildVersion,
pub git_commit_id: String,
pub initialized: bool,
pub canister_ids: CanisterIds,
pub airdrops: AirdropsMetrics,
}
Expand Down
15 changes: 15 additions & 0 deletions backend/libraries/utils/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ pub const HOUR_IN_MS: Milliseconds = MINUTE_IN_MS * 60;
pub const DAY_IN_MS: Milliseconds = HOUR_IN_MS * 24;
pub const WEEK_IN_MS: Milliseconds = DAY_IN_MS * 7;

pub const MONTHS: [&str; 12] = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];

pub const NANOS_PER_MILLISECOND: u64 = 1_000_000;

pub fn now_millis() -> TimestampMillis {
Expand Down
Loading