Skip to content
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 2 commits into from
Apr 3, 2023
Merged

modify: refactor code #473

merged 2 commits into from
Apr 3, 2023

Conversation

mkXultra
Copy link
Contributor

@mkXultra mkXultra commented Apr 3, 2023

No description provided.

@mkXultra mkXultra self-assigned this Apr 3, 2023
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
Copy link

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

  1. 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.
  2. 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.
  3. 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.
  4. 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
Copy link

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 the CollectedAmount field of the listing parameter. Instead of updating the parameter itself, it should create a new copy of the parameter and update its CollectedAmount field.
  • The return type of the SafeCloseBidCollectDeposit function should be changed from types.NftListing to sdk.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 the IsPositive() 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.

@mkXultra mkXultra merged commit 6cd3b56 into newDevelop Apr 3, 2023
@mkXultra mkXultra deleted the feature/refactor_nftmarket branch April 3, 2023 10:04
taiki1frsh pushed a commit that referenced this pull request Apr 4, 2023
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.

1 participant