-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
modify: refactor code #473
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (k Keeper) SafeCloseBidWithAllInterest(ctx sdk.Context, bid types.NftBid) error { | ||
bidder, err := sdk.AccAddressFromBech32(bid.Bidder) | ||
if err != nil { | ||
return err | ||
} | ||
interestAmount := bid.TotalInterestAmount(ctx.BlockTime()) | ||
if interestAmount.Amount.GT(sdk.ZeroInt()) { | ||
if interestAmount.Amount.IsPositive() { | ||
err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, bidder, sdk.Coins{sdk.NewCoin(interestAmount.Denom, interestAmount.Amount)}) | ||
if err != nil { | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the code review for this patch
- The patch looks good, however it would be better to add a comment before the new added lines (todo make unit test) to explain the purpose of that line.
- The function SafeCloseBidCollectDeposit has been changed to return CollectedAmount instead of listing. It would be nice to add a comment to explain why the change was made.
- The if condition in SafeCloseBidWithAllInterest has been changed from GT(sdk.ZeroInt()) to IsPositive(). It would be better to add a comment to explain why the change was made.
- The patch should include unit tests to ensure the changes are working as expected.
func (k Keeper) SafeCloseBidWithAllInterest(ctx sdk.Context, bid types.NftBid) error { | ||
bidder, err := sdk.AccAddressFromBech32(bid.Bidder) | ||
if err != nil { | ||
return err | ||
} | ||
interestAmount := bid.TotalInterestAmount(ctx.BlockTime()) | ||
if interestAmount.Amount.GT(sdk.ZeroInt()) { | ||
if interestAmount.Amount.IsPositive() { | ||
err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, bidder, sdk.Coins{sdk.NewCoin(interestAmount.Denom, interestAmount.Amount)}) | ||
if err != nil { | ||
return err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code review for the given patch is as follows:
- In the
SafeCloseBidCollectDeposit
function, there seems to be a mistake in updating theCollectedAmount
field of thelisting
parameter. Instead of updating the parameter itself, it should create a new copy of the parameter and update itsCollectedAmount
field. - The return type of the
SafeCloseBidCollectDeposit
function should be changed fromtypes.NftListing
tosdk.Coin
, since only the collected amount needs to be returned. - The
SafeCloseBidWithAllInterest
function has a TODO comment to add unit tests, which should be addressed. - Instead of checking if
interestAmount.Amount
is greater than zero, use theIsPositive()
method provided by the SDK. - Overall, the code looks good with no obvious bug risks. However, since we do not have the full context of the system, there might be some issues specific to this codebase that could not be captured here. Therefore, careful testing and review of the entire system are still necessary.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.