Skip to content

Commit

Permalink
WIP: Trivia Index Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
D9J9V committed Sep 1, 2024
1 parent 7afbb54 commit d204882
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/vara/factory/app/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl From<sails_rs::errors::Error> for TriviaError {
pub struct TriviaFactoryState {
trivias: Vec<Trivia>,
owner: ActorId,
trivia_count: u32,
}

struct TriviaService {
Expand All @@ -64,6 +65,7 @@ impl TriviaService {
state: TriviaFactoryState {
trivias: Vec::new(),
owner: msg::source(),
trivia_count: 0,
},
}
}
Expand All @@ -81,14 +83,15 @@ impl TriviaService {
msg::send(exec::program_id(), Vec::<u8>::new(), reward)
.map_err(|_| TriviaError::RewardTransferFailed)?;

let index = self.state.trivias.len() as u32;
let index = self.state.trivia_count;
self.state.trivias.push(Trivia {
questions,
correct_answers,
reward,
owner: msg::source(),
is_completed: false,
});
self.state.trivia_count += 1;

self.notify_on(TriviaEvent::TriviaCreated { index })?;
Ok(index) // Cambiado de Ok(()) a Ok(index)
Expand Down Expand Up @@ -151,7 +154,7 @@ impl TriviaService {
}

pub fn get_trivia_count(&self) -> u32 {
self.state.trivias.len() as u32
self.state.trivia_count
}

pub fn update_trivia(
Expand Down

0 comments on commit d204882

Please sign in to comment.