Skip to content

Commit

Permalink
fix: fixed addDelegate and removeDelegate emitting events when not ne…
Browse files Browse the repository at this point in the history
…cessary
  • Loading branch information
0xNilesh committed Nov 20, 2024
1 parent e5ff018 commit 6bcf5ba
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,20 @@ pub mod PushComm {

fn add_delegate(ref self: ContractState, delegate: ContractAddress) {
let channel = get_caller_address();
self.delegated_notification_senders.entry(channel).write(delegate, true);
self.emit(AddDelegate { channel: channel, delegate: delegate });

if !self.delegated_notification_senders.entry(channel).entry(delegate).read() {
self.delegated_notification_senders.entry(channel).write(delegate, true);
self.emit(AddDelegate { channel: channel, delegate: delegate });
}
}

fn remove_delegate(ref self: ContractState, delegate: ContractAddress) {
let channel = get_caller_address();
self.delegated_notification_senders.entry(channel).write(delegate, false);
self.emit(RemoveDelegate { channel: channel, delegate: delegate });

if self.delegated_notification_senders.entry(channel).entry(delegate).read() {
self.delegated_notification_senders.entry(channel).write(delegate, false);
self.emit(RemoveDelegate { channel: channel, delegate: delegate });
}
}

fn send_notification(
Expand Down

0 comments on commit 6bcf5ba

Please sign in to comment.