Skip to content

Commit

Permalink
Fix second part of id (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
DZakh authored Sep 17, 2024
1 parent 5b9be2c commit e72019c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions codegenerator/cli/src/hbs_templating/contract_import_templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,21 @@ pub struct Event {
}

impl Event {
fn get_entity_id_code(event_var_name: String, language: &Language) -> String {
fn get_entity_id_code(event_var_name: String, is_fuel: bool, language: &Language) -> String {
let to_string_code = match language {
Language::ReScript => "->Belt.Int.toString",
Language::TypeScript => "",
Language::JavaScript => "",
}
.to_string();

let second_part = match is_fuel {
true => format!("${{{event_var_name}.transaction.id}}"),
false => format!("${{{event_var_name}.block.number}}"),
};

format!(
"`${{{event_var_name}.chainId}}_${{{event_var_name}.block.\
number}}_${{{event_var_name}.logIndex{}}}`",
"`${{{event_var_name}.chainId}}_{second_part}_${{{event_var_name}.logIndex{}}}`",
to_string_code
)
}
Expand Down Expand Up @@ -333,7 +337,11 @@ impl Event {

Ok(Event {
name: event.name.to_capitalized_options(),
entity_id_from_event_code: Event::get_entity_id_code("event".to_string(), &language),
entity_id_from_event_code: Event::get_entity_id_code(
"event".to_string(),
is_fuel,
&language,
),
create_mock_code: Event::get_create_mock_code(&event, &contract, is_fuel, &language),
params,
})
Expand Down

0 comments on commit e72019c

Please sign in to comment.