Skip to content

Conversation

@reuvenpo
Copy link
Contributor

This PR implements only the bug fix from #16 .

The bug was that if allowance is increased or decreased after the previously provided allowance has expired, then the allowance didn't reset and the new allowance would be added or deducted from the expired allowance.

Comment on lines 995 to 997

if allowance.expiration.map(|ex| ex < env.block.time) == Some(true) && allowance.amount != 0 {
allowance.amount = 0;
write_allowance(storage, owner, spender, allowance)?;
if allowance.is_expired_at(&env.block) {
return Err(insufficient_allowance(0, amount));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to reviewer: This code segment was expensive and unnecessary. There's no need to actively set the amount to 0 if the allowance query would make it clear to consumers that the allowance has expired anyway (so the amount isn't important)

@Cashmaney Cashmaney merged commit d335872 into master May 27, 2021
@reuvenpo reuvenpo deleted the expired-allowance-reset branch May 27, 2021 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants