BibliothecaDAO / eternum

onchain eternal game
https://alpha-eternum.realms.world
MIT License
36 stars 30 forks source link

feat: make quests claiming multicall #1025

Closed edisontim closed 6 days ago

edisontim commented 1 week ago

User description

Closes #1019


PR Type

Enhancement


Description


Changes walkthrough πŸ“

Relevant files
Enhancement
createSystemCalls.ts
Rename CreateStartingResources to MintStartingResources in system
calls

client/src/dojo/createSystemCalls.ts
  • Renamed CreateStartingResources to MintStartingResources in the
    mint_starting_resources function.
  • +1/-1     
    HintBox.tsx
    Refactor quest resource claiming to use multicall               

    client/src/ui/components/hints/HintBox.tsx
  • Reordered imports for better readability.
  • Removed handleClaimResources function.
  • Updated handleAllClaims to use mint_starting_resources with multiple
    config_ids.
  • +11/-28 
    index.ts
    Enhance `mint_starting_resources` to support multicall     

    sdk/packages/eternum/src/provider/index.ts
  • Updated mint_starting_resources to handle multiple config_ids in a
    single transaction.
  • +10/-7   
    provider.ts
    Update MintStartingResources interface to support multiple config IDs

    sdk/packages/eternum/src/types/provider.ts
  • Renamed CreateStartingResources interface to MintStartingResources.
  • Changed config_id to config_ids as an array in the interface.
  • +2/-2     

    πŸ’‘ PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    vercel[bot] commented 1 week ago

    The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

    Name Status Preview Comments Updated (UTC)
    eternum βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Jun 26, 2024 1:32pm
    github-actions[bot] commented 1 week ago

    PR Reviewer Guide πŸ”

    ⏱️ Estimated effort to review [1-5] 3
    πŸ§ͺ Relevant tests No
    πŸ”’ Security concerns No
    ⚑ Key issues to review Possible Bug:
    The refactoring from a single config_id to config_ids array in the mint_starting_resources function might cause issues if not all calling functions have been updated to pass an array instead of a single value.
    Performance Concern:
    The change to multicall in mint_starting_resources could lead to increased gas costs or unexpected behavior if not handled properly in all scenarios.
    github-actions[bot] commented 1 week ago

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Best practice
    Enhance clarity by using parameter destructuring directly in the function signature ___ **Use destructuring directly in the function parameter to enhance code clarity and reduce
    redundancy.** [sdk/packages/eternum/src/provider/index.ts [542-553]](https://github.com/BibliothecaDAO/eternum/pull/1025/files#diff-467989f145beaf5796d645b8891d6c2468a39d539d62b48a1459185c6fe1de55R542-R553) ```diff -public async mint_starting_resources(props: SystemProps.MintStartingResources) { - const { realm_entity_id, config_ids, signer } = props; +public async mint_starting_resources({ realm_entity_id, config_ids, signer }: SystemProps.MintStartingResources) { return await this.executeAndCheckTransaction( signer, config_ids.map((configId) => ({ contractAddress: getContractByName(this.manifest, "realm_systems"), entrypoint: "mint_starting_resources", calldata: [configId, realm_entity_id], }), ); } ```
    Suggestion importance[1-10]: 9 Why: Using destructuring directly in the function parameter enhances code clarity and reduces redundancy, making the function signature cleaner and more readable.
    9
    Maintainability
    Simplify control flow by refactoring nested try-catch blocks into a single block ___ **Refactor the nested try-catch blocks in handleAllClaims to a single try-catch block to
    simplify the control flow and improve readability.** [client/src/ui/components/hints/HintBox.tsx [28-38]](https://github.com/BibliothecaDAO/eternum/pull/1025/files#diff-5cf22aac8f0607d764110992d7cb5eac12ced82af11478c86e79fd3659cefc6aR28-R38) ```diff try { - try { - await mint_starting_resources({ - signer: account, - config_ids: quest.prizes.map((prize) => BigInt(prize.id)), - realm_entity_id: entityId || "0", - }); - } catch (error) { - console.error(`Failed to claim resources for quest ${quest.name}:`, error); - } + await mint_starting_resources({ + signer: account, + config_ids: quest.prizes.map((prize) => BigInt(prize.id)), + realm_entity_id: entityId || "0", + }); } catch (error) { - console.error("Failed to claim resources:", error); + console.error(`Failed to claim resources:`, error); } ```
    Suggestion importance[1-10]: 8 Why: The suggestion to refactor the nested try-catch blocks into a single block improves readability and simplifies the control flow, making the code easier to maintain.
    8
    Enhancement
    Improve naming consistency and clarity by renaming the interface ___ **Rename the MintStartingResources interface to MintResourcesProps to better reflect its
    usage and align with naming conventions.** [sdk/packages/eternum/src/types/provider.ts [322-325]](https://github.com/BibliothecaDAO/eternum/pull/1025/files#diff-3d3d05c5e7f20c103bd35e9560b88dc343f73afc5b5116cd75f3d9c382bfe574R322-R325) ```diff -export interface MintStartingResources extends SystemSigner { +export interface MintResourcesProps extends SystemSigner { config_ids: num.BigNumberish[]; realm_entity_id: num.BigNumberish; } ```
    Suggestion importance[1-10]: 7 Why: Renaming the interface to `MintResourcesProps` improves naming consistency and clarity, aligning better with common naming conventions. However, this change is more of an enhancement rather than a critical improvement.
    7