-
Notifications
You must be signed in to change notification settings - Fork 5
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
Transferable vs available balance! address #1071 #1078
Conversation
WalkthroughThe recent updates enhance balance management in the PolkaGate extension, focusing on accurate calculation and display of transferable balances. Key improvements include the introduction of a new Changes
Assessment against linked issues
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
Review Status
Configuration used: CodeRabbit UI
Files selected for processing (4)
- packages/extension-polkagate/src/fullscreen/accountDetailsFullScreen/index.tsx (1 hunks)
- packages/extension-polkagate/src/hooks/useBalances.ts (3 hunks)
- packages/extension-polkagate/src/popup/account/util.ts (3 hunks)
- packages/extension-polkagate/src/util/types.ts (1 hunks)
Additional comments not posted (4)
packages/extension-polkagate/src/popup/account/util.ts (1)
36-39
: The updated logic for calculating the 'transferable' balance in thegetValue
function correctly considers thefrozenBalance
andreservedBalance
. This change aligns with the PR objectives to accurately calculate and display the transferable balance.packages/extension-polkagate/src/hooks/useBalances.ts (1)
104-117
: The addition offrozenBalance
handling in thegetBalances
function is a significant improvement. It ensures that thefrozenBalance
is accurately retrieved from the system account data and included in thenewBalances
state, aligning with the PR objectives to accurately calculate and display the transferable balance.packages/extension-polkagate/src/fullscreen/accountDetailsFullScreen/index.tsx (1)
230-230
: The modification to use thegetValue
function for retrieving the 'Transferable' balance in theAccountDetails
component is a positive change. It ensures that the balance displayed is calculated based on the updated logic that considers thefrozenBalance
, aligning with the PR objectives.packages/extension-polkagate/src/util/types.ts (1)
619-619
: The addition of thefrozenBalance
field to theBalancesInfo
interface is crucial for supporting the updated logic for calculating and displaying the transferable balance. This change ensures that the type definitions are aligned with the PR objectives.
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.
Actionable comments posted: 1
Review Status
Configuration used: CodeRabbit UI
Files selected for processing (6)
- packages/extension-polkagate/src/hooks/useAssetsBalances.ts (3 hunks)
- packages/extension-polkagate/src/popup/account/util.ts (3 hunks)
- packages/extension-polkagate/src/util/workers/getAssetOnAssetHub.js (1 hunks)
- packages/extension-polkagate/src/util/workers/getAssetOnRelayChain.js (2 hunks)
- packages/extension-polkagate/src/util/workers/utils/balancify.js (2 hunks)
- packages/extension-polkagate/src/util/workers/utils/toGetNativeToken.js (2 hunks)
Files skipped from review as they are similar to previous changes (1)
- packages/extension-polkagate/src/popup/account/util.ts
Additional comments not posted (6)
packages/extension-polkagate/src/util/workers/utils/balancify.js (2)
8-8
: The addition offrozenBalance
to thebalancify
function aligns with the PR objectives and follows the existing pattern for handling balance fields. Good job ensuring consistency.
22-22
: The change inbalancifyAsset
from usingbalances.availableBalance
tobalances.free
foravailableBalance
seems to reflect a significant logic adjustment. Please ensure this change accurately represents the intended balance calculations and does not introduce discrepancies.packages/extension-polkagate/src/util/workers/utils/toGetNativeToken.js (1)
11-15
: FetchingsystemBalance
for each address and updatingfrozenBalance
accordingly aligns with the PR objectives. However, consider adding error handling and type checking when assigningfrozenBalance
to ensure robustness against potential changes in thesystemBalance
response structure.packages/extension-polkagate/src/util/workers/getAssetOnAssetHub.js (1)
46-47
: The introduction offreeBalance
andfrozenBalance
fields ingetAssetOnAssetHub
function is consistent with the PR objectives and is implemented clearly. Consider refining the comment "JUST to comply with the rule ..." to provide more context or clarity on the rule being referred to.packages/extension-polkagate/src/util/workers/getAssetOnRelayChain.js (1)
57-60
: RetrievingsystemBalance
for each address and updatingfrozenBalance
accordingly aligns with the PR objectives. Consider adding error handling and type checking when assigningfrozenBalance
to ensure robustness against potential changes in thesystemBalance
response structure.packages/extension-polkagate/src/hooks/useAssetsBalances.ts (1)
64-64
: AddingfrozenBalance
toBN_MEMBERS
aligns with the PR objectives and ensures consistency across balance-related functionalities.
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.
Actionable comments posted: 0
Review Status
Configuration used: CodeRabbit UI
Files selected for processing (6)
- packages/extension-polkagate/src/fullscreen/governance/post/decisionDeposit/index.tsx (6 hunks)
- packages/extension-polkagate/src/fullscreen/sendFund/InputPage.tsx (8 hunks)
- packages/extension-polkagate/src/popup/crowdloans/contribute/Contribute.tsx (4 hunks)
- packages/extension-polkagate/src/popup/send/index.tsx (3 hunks)
- packages/extension-polkagate/src/popup/staking/pool/stake/StakeInitialChoice.tsx (1 hunks)
- packages/extension-polkagate/src/popup/staking/pool/stake/bondExtra/index.tsx (7 hunks)
Additional comments not posted (22)
packages/extension-polkagate/src/popup/staking/pool/stake/StakeInitialChoice.tsx (1)
63-63
: The TODO comment about considering the frozen amount for staking is noted. It's good practice to track such enhancements or potential fixes. Consider creating an issue or task in your project management tool to ensure this doesn't get overlooked.packages/extension-polkagate/src/popup/staking/pool/stake/bondExtra/index.tsx (4)
49-51
: IntroducedtransferableBalance
to consider the total possible staking amount. This is a good practice for clarity and maintainability, ensuring that the balance calculations are based on the correct balance type.
62-71
: The logic to set the maximum staking amount consideringtransferableBalance
and estimated fees is correctly implemented. This ensures that the user does not stake more than they can afford after accounting for fees.
99-119
: > 📝 NOTEThis review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [92-105]
The fee estimation logic for both the staking amount and the maximum possible staking amount is well-handled. It's important to keep the user informed about potential transaction costs.
108-116
: The check to disable the "Next" button based on the staking amount being in range and other conditions is correctly implemented. This prevents users from proceeding with invalid or problematic inputs.packages/extension-polkagate/src/popup/send/index.tsx (5)
32-32
: ImportinggetValue
to retrievetransferableBalance
is a good approach for more accurate balance handling in the context of transfers.
57-57
: UsingtransferableBalance
for balance calculations instead of directly accessingbalances?.availableBalance
ensures that the logic considers only the amount that can actually be transferred, improving accuracy.
64-73
: The logic to set the whole amount based ontransferableBalance
correctly accounts for fees and existential deposit, ensuring users don't transfer more than they can afford or drop below the existential deposit.
80-83
: Adjusting the logic to check if the amount is less than the transferable balance before enabling the transfer button is a prudent safety measure.
125-127
: Updating the call to thetransfer
function to usetransferableBalance
instead ofbalances
is a logical step following the introduction oftransferableBalance
. This ensures consistency in the balance used throughout the transfer logic.packages/extension-polkagate/src/popup/crowdloans/contribute/Contribute.tsx (5)
27-27
: Importing and usinggetValue
to calculatetransferableBalance
is a good practice, ensuring that the logic operates on the correct balance type for contributions.
57-57
: UsingtransferableBalance
for balance-related calculations in the context of crowdloan contributions ensures that the logic is based on the amount that is actually available for transfer, enhancing accuracy.
69-74
: The fee estimation logic consideringtransferableBalance
is correctly implemented, ensuring that users are informed about potential transaction costs accurately.
81-84
: The logic to disable the "Next" button based on the contribution amount being in range and other conditions is correctly implemented, preventing users from proceeding with invalid or problematic inputs.
91-100
: Setting the maximum contribution amount consideringtransferableBalance
and estimated fees is correctly implemented, ensuring that users do not contribute more than they can afford after accounting for fees.packages/extension-polkagate/src/fullscreen/governance/post/decisionDeposit/index.tsx (2)
20-20
: Replacing the import ofbroadcast
withgetValue
and removing unused imports and components cleans up the code and focuses on the necessary functionality for decision deposit handling.
129-129
: Adjusting the calculation ofnotEnoughBalance
by usinggetValue
to retrievetransferableBalance
ensures that the logic checks against the correct balance type, improving the accuracy of the check.packages/extension-polkagate/src/fullscreen/sendFund/InputPage.tsx (5)
19-19
: ImportinggetValue
to calculatetransferableBalance
is a good approach for more accurate balance handling in the context of fund transfers.
85-85
: IntroducingtransferableBalance
for balance calculations instead of directly accessingbalances?.availableBalance
ensures that the logic considers only the amount that can actually be transferred, improving accuracy.
82-105
: > 📝 NOTEThis review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [94-112]
The logic to display warning messages based on
transferableBalance
and other conditions is correctly implemented, ensuring users are informed about potential issues before proceeding with the transfer.
272-277
: Calculating the maximum fee based ontransferableBalance
is a prudent approach to ensure that users are aware of the maximum potential cost of their transfer, aiding in decision-making.
311-324
: The logic to set the whole amount based ontransferableBalance
, considering fees and existential deposit, is correctly implemented. This ensures users don't transfer more than they can afford or drop below the existential deposit.
Needs more check on Acala! |
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.
Actionable comments posted: 1
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- packages/extension-polkagate/src/fullscreen/accountDetails/index.tsx (3 hunks)
- packages/extension-polkagate/src/fullscreen/governance/post/decisionDeposit/index.tsx (4 hunks)
Additional context used
Learnings (1)
packages/extension-polkagate/src/fullscreen/accountDetails/index.tsx (1)
Learnt from: AMIRKHANEF PR: PolkaGate/extension#1394 File: packages/extension-polkagate/src/fullscreen/accountDetails/components/ReservedDisplayBalance.tsx:0-0 Timestamp: 2024-07-01T09:27:24.482Z Learning: When checking for NaN values, always use `Number.isNaN` instead of `isNaN` to avoid unexpected type coercions.
Biome
packages/extension-polkagate/src/fullscreen/governance/post/decisionDeposit/index.tsx
[error] 22-22: Do not shadow the global "Proxy" property.
Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.
(lint/suspicious/noShadowRestrictedNames)
Additional comments not posted (4)
packages/extension-polkagate/src/fullscreen/governance/post/decisionDeposit/index.tsx (2)
49-49
: Improved readability with consistent formatting.The added space after the function name aligns with common formatting practices, enhancing readability.
128-128
: Enhanced balance check logic usinggetValue
.Using
getValue('transferable', balances)
to retrieve the transferable balance improves the clarity and flexibility of the balance sufficiency check.packages/extension-polkagate/src/fullscreen/accountDetails/index.tsx (2)
8-8
: Improved type safety withBalancesInfo
.Importing
BalancesInfo
enhances the type safety and clarity of balance data handling, aligning with best practices for structured data management.
227-227
: Refined balance retrieval logic usinggetValue
.Using
getValue('Transferable', balancesToShow as BalancesInfo)
for theamount
prop ensures accurate and maintainable balance retrieval.
import { getValue } from '../../../../popup/account/util'; | ||
import { Proxy, ProxyItem, TxInfo } from '../../../../util/types'; |
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.
Avoid shadowing restricted global names.
The Proxy
type imported here shadows the global Proxy
object in JavaScript, which can lead to confusion. Consider renaming this type to avoid potential issues.
- import { Proxy, ProxyItem, TxInfo } from '../../../../util/types';
+ import { Proxy as CustomProxy, ProxyItem, TxInfo } from '../../../../util/types';
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
import { getValue } from '../../../../popup/account/util'; | |
import { Proxy, ProxyItem, TxInfo } from '../../../../util/types'; | |
import { getValue } from '../../../../popup/account/util'; | |
import { Proxy as CustomProxy, ProxyItem, TxInfo } from '../../../../util/types'; |
Tools
Biome
[error] 22-22: Do not shadow the global "Proxy" property.
Consider renaming this variable. It's easy to confuse the origin of variables when they're named after a known global.
(lint/suspicious/noShadowRestrictedNames)
@AMIRKHANEF can u do the checks plz |
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.
Actionable comments posted: 0
Outside diff range, codebase verification and nitpick comments (1)
packages/extension-polkagate/src/hooks/useBalances.ts (1)
101-120
: Consider using optional chaining.The
useBalances
hook correctly includesfrozenBalance
, enhancing balance data completeness. Consider using optional chaining for accessingformatted
.- formatted && api.derive.balances?.all(formatted).then((allBalances) => { + api.derive.balances?.all(formatted)?.then((allBalances) => {Tools
Biome
[error] 117-117: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- packages/extension-polkagate/src/fullscreen/accountDetails/index.tsx (4 hunks)
- packages/extension-polkagate/src/hooks/useBalances.ts (4 hunks)
- packages/extension-polkagate/src/popup/account/util.ts (3 hunks)
- packages/extension-polkagate/src/util/workers/getAssetOnRelayChain.js (3 hunks)
Files skipped from review as they are similar to previous changes (1)
- packages/extension-polkagate/src/fullscreen/accountDetails/index.tsx
Additional context used
Biome
packages/extension-polkagate/src/hooks/useBalances.ts
[error] 117-117: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
Additional comments not posted (5)
packages/extension-polkagate/src/popup/account/util.ts (2)
13-15
: LGTM!The
isEmptyObject
function correctly checks if an object is empty.
Line range hint
16-41
: LGTM!The modifications to the
getValue
function enhance its robustness by handling empty objects and implementing logic for'transferable'
balances.packages/extension-polkagate/src/util/workers/getAssetOnRelayChain.js (3)
Line range hint
16-34
: LGTM!The
getPooledBalance
function is correctly implemented, and the use of optional chaining enhances robustness.
Line range hint
54-74
: LGTM!The
getBalances
function correctly includesfrozenBalance
, enriching the balance data.
Line range hint
85-126
: LGTM!The
getAssetOnRelayChain
function is correctly implemented, and the cosmetic changes are appropriate.
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.
Actionable comments posted: 0
Outside diff range, codebase verification and nitpick comments (3)
packages/extension-polkagate/src/popup/account/unlock/LockedInReferenda.tsx (2)
31-31
: Function Declaration Style: Maintain consistency.The function declaration style was altered slightly by adding a space. Ensure consistency in coding style across the codebase.
- export default function LockedInReferenda({ address, refresh, setRefresh }: Props): React.ReactElement<Props> { + export default function LockedInReferenda ({ address, refresh, setRefresh }: Props): React.ReactElement<Props> {
Line range hint
43-49
: Redundant Conditional Check: Simplify logic.The check for
referendaLocks === null
and subsequent return can be simplified by handling undefined or null values together.- if (referendaLocks === null) { - setLockedInReferenda(BN_ZERO); - setTimeToUnlock(null); - return; - } + if (!referendaLocks) { + setLockedInReferenda(referendaLocks === null ? BN_ZERO : undefined); + setTimeToUnlock(referendaLocks === null ? null : undefined); + return; }packages/extension-polkagate/src/hooks/useTimeToUnlock.tsx (1)
4-4
: Type Import Issue:PalletBalancesBalanceLock
Not Found in@polkadot/types/lookup
.The type
PalletBalancesBalanceLock
is not present in the@polkadot/types/lookup
package, which suggests that the import statement is incorrect or outdated.
- Check the package documentation or source to verify the correct type name or location.
- Update the import statement accordingly to reflect the correct type.
Analysis chain
Type Import Issue: Verify the existence of
PalletBalancesBalanceLock
.The import from
@polkadot/types/lookup
is flagged as problematic. Verify the existence and correctness of this type.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the existence of `PalletBalancesBalanceLock` in `@polkadot/types/lookup`. # Test: Check if `PalletBalancesBalanceLock` is exported from `@polkadot/types/lookup`. rg --type ts 'PalletBalancesBalanceLock' | rg '@polkadot/types/lookup'Length of output: 367
Script:
#!/bin/bash # Description: Check if `PalletBalancesBalanceLock` exists in the `@polkadot/types/lookup` package. # Search for the definition or export of `PalletBalancesBalanceLock` in the package. rg 'PalletBalancesBalanceLock' $(fd 'lookup' | grep '@polkadot/types')Length of output: 495
Tools
GitHub Check: build
[failure] 4-4:
Module '"@polkadot/types/lookup"' has no exported member 'PalletBalancesBalanceLock'.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (9)
- packages/extension-polkagate/src/fullscreen/accountDetails/components/LockedInReferendaFS.tsx (4 hunks)
- packages/extension-polkagate/src/fullscreen/accountDetails/components/index.ts (1 hunks)
- packages/extension-polkagate/src/fullscreen/accountDetails/index.tsx (7 hunks)
- packages/extension-polkagate/src/hooks/index.ts (1 hunks)
- packages/extension-polkagate/src/hooks/useTimeToUnlock.tsx (1 hunks)
- packages/extension-polkagate/src/popup/account/Others.tsx (3 hunks)
- packages/extension-polkagate/src/popup/account/index.tsx (1 hunks)
- packages/extension-polkagate/src/popup/account/unlock/LockedInReferenda.tsx (4 hunks)
- packages/extension-polkagate/src/popup/staking/solo/index.tsx (3 hunks)
Files skipped from review due to trivial changes (2)
- packages/extension-polkagate/src/popup/account/Others.tsx
- packages/extension-polkagate/src/popup/staking/solo/index.tsx
Files skipped from review as they are similar to previous changes (1)
- packages/extension-polkagate/src/fullscreen/accountDetails/index.tsx
Additional context used
GitHub Check: build
packages/extension-polkagate/src/hooks/useTimeToUnlock.tsx
[failure] 4-4:
Module '"@polkadot/types/lookup"' has no exported member 'PalletBalancesBalanceLock'.
Additional comments not posted (10)
packages/extension-polkagate/src/fullscreen/accountDetails/components/index.ts (1)
10-10
: Export Update: Consider the impact of replacingLockedBalanceDisplay
.The export replacement of
LockedBalanceDisplay
withLockedInReferendaFS
suggests a functional shift. Ensure that all dependent components or modules are updated to useLockedInReferendaFS
where necessary.packages/extension-polkagate/src/popup/account/unlock/LockedInReferenda.tsx (2)
Line range hint
64-82
: Sorting Logic: Ensure stability and correctness.The sorting logic for
referendaLocks
is crucial for determining the biggest vote. Ensure the sort function is stable and correctly prioritizes locks.Verification successful
Sorting Logic Verified: Stability and Correctness Ensured
The sorting logic for
referendaLocks
is implemented in theuseTimeToUnlock
function, where locks are sorted bytotal
andendBlock
in descending order. This ensures that the biggest vote is correctly prioritized. The logic appears stable and correct as per the criteria mentioned.
- File:
packages/extension-polkagate/src/hooks/useTimeToUnlock.tsx
- Relevant Code:
referendaLocks.sort((a, b) => { if (a.total.gt(b.total)) { return -1; } if (a.total.lt(b.total)) { return 1; } return a.endBlock.gt(b.endBlock) ? -1 : 1; });Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the sorting logic for `referendaLocks`. # Test: Check if the sorting logic is stable and correctly implemented. ast-grep --lang typescript --pattern $'referendaLocks.sort((a, b) => { $$$ })'Length of output: 79
Script:
#!/bin/bash # Search for any usage of `referendaLocks` in the codebase to identify sorting logic or relevant operations. rg 'referendaLocks' -A 5Length of output: 9532
35-39
: Improved State Management: Verify hook functionality.The introduction of
useInfo
,useTokenPrice
, anduseTimeToUnlock
hooks simplifies state management. Ensure these hooks are functioning correctly and efficiently.Verification successful
Hook Implementations and Usage Verified
The hooks
useInfo
,useTokenPrice
, anduseTimeToUnlock
are defined and used across multiple files in the codebase. They are imported from a centralhooks
directory, indicating they are custom hooks likely defined within this project. The implementations are as follows:
useInfo
: Defined inuseInfo.ts
and used extensively across various components to retrieve account and chain information.useTokenPrice
: Defined inuseTokenPrice.ts
and used to fetch token price information.useTimeToUnlock
: Defined inuseTimeToUnlock.tsx
and used to calculate time-related unlocking data.These hooks are correctly implemented and imported, ensuring they function as intended in managing state efficiently across the application.
- Files of interest include:
packages/extension-polkagate/src/hooks/useInfo.ts
packages/extension-polkagate/src/hooks/useTokenPrice.ts
packages/extension-polkagate/src/hooks/useTimeToUnlock.tsx
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the implementation of the `useInfo`, `useTokenPrice`, and `useTimeToUnlock` hooks. # Test: Search for the implementations of these hooks to ensure they are correctly defined. ast-grep --lang typescript --pattern 'function useInfo($_) { $$$ }' ast-grep --lang typescript --pattern 'function useTokenPrice($_) { $$$ }' ast-grep --lang typescript --pattern 'function useTimeToUnlock($_) { $$$ }'Length of output: 223
Script:
#!/bin/bash # Description: Search for the implementations of the `useInfo`, `useTokenPrice`, and `useTimeToUnlock` hooks with adjusted patterns. # Search for the useInfo hook ast-grep --lang typescript --pattern 'const useInfo = ($_: any) => { $$$ }' # Search for the useTokenPrice hook ast-grep --lang typescript --pattern 'const useTokenPrice = ($_: any) => { $$$ }' # Search for the useTimeToUnlock hook ast-grep --lang typescript --pattern 'const useTimeToUnlock = ($_: any) => { $$$ }'Length of output: 247
Script:
#!/bin/bash # Description: Search for import statements and alternative patterns for the hooks. # Search for import statements of the hooks rg 'import { useInfo }' -A 2 rg 'import { useTokenPrice }' -A 2 rg 'import { useTimeToUnlock }' -A 2 # Search for hooks defined with different patterns ast-grep --lang typescript --pattern 'export function useInfo($_) { $$$ }' ast-grep --lang typescript --pattern 'export function useTokenPrice($_) { $$$ }' ast-grep --lang typescript --pattern 'export function useTimeToUnlock($_) { $$$ }'Length of output: 695
Script:
#!/bin/bash # Description: Correct the regex syntax and search for mentions of the hooks in the codebase. # Corrected search for import statements of the hooks rg 'import.*useInfo' -A 2 rg 'import.*useTokenPrice' -A 2 rg 'import.*useTimeToUnlock' -A 2 # Search for any mention of the hooks in the codebase rg 'useInfo' rg 'useTokenPrice' rg 'useTimeToUnlock'Length of output: 95560
packages/extension-polkagate/src/hooks/useTimeToUnlock.tsx (2)
27-31
: Use ofbiggestOngoingLock
: Ensure correctness.The
biggestOngoingLock
function is used to determine the largest ongoing lock. Ensure this logic accurately reflects the intended functionality.Verification successful
Use of
biggestOngoingLock
is CorrectThe
biggestOngoingLock
function is implemented and used correctly in the codebase. It accurately determines the largest ongoing lock by checking for locks with anendBlock
equal toBN_MAX_INTEGER
and is used appropriately in the logic to compare againstbiggestVote
. No issues were found.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the implementation of `biggestOngoingLock`. # Test: Check if `biggestOngoingLock` is correctly implemented and used. ast-grep --lang typescript --pattern $'const biggestOngoingLock = useCallback(($$$) => { $$$ })'Length of output: 97
Script:
#!/bin/bash # Search for the definition of `biggestOngoingLock` in the codebase rg 'const biggestOngoingLock = useCallback' -A 5 # Search for all usages of `biggestOngoingLock` in the codebase rg 'biggestOngoingLock'Length of output: 1060
112-127
: API Query Logic: Confirm balance lock retrieval.Ensure that the API query for balance locks is correctly implemented and retrieves the expected data.
Verification successful
API Query Logic Verified: Balance lock retrieval is correctly implemented.
The API query for balance locks is present and correctly implemented in the
useTimeToUnlock.tsx
file. The logic checks for locks and retrieves the expected data based on the specified conditions.
- Verified in
packages/extension-polkagate/src/hooks/useTimeToUnlock.tsx
.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the API query for balance locks. # Test: Ensure the API query for `balances.locks` is correctly implemented. ast-grep --lang typescript --pattern $'api.query[\'balances\'][\'locks\']($_).then(($$) => { $$$ })'Length of output: 109
Script:
#!/bin/bash # Use ripgrep to search for the specific API query pattern in the codebase. rg "api\.query\['balances'\]\['locks'\]" -A 5Length of output: 662
packages/extension-polkagate/src/fullscreen/accountDetails/components/LockedInReferendaFS.tsx (3)
30-30
: Component renaming is appropriate.Renaming the component to
LockedInReferendaFS
aligns with its purpose of displaying locked referenda information. Ensure that all references to the old component name have been updated.
15-18
: Ensure correct usage of hooks.The
useInfo
hook now providesdecimal
andtoken
directly, which simplifies the component. Ensure thatuseInfo
is correctly returning these values for all possibleaddress
inputs.Verification successful
The
useInfo
hook correctly returnsdecimal
andtoken
. TheuseInfo
function includes bothdecimal
andtoken
in its return statement, ensuring these values are provided for all address inputs. This satisfies the review comment's requirement.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the `useInfo` hook returns `decimal` and `token` correctly for all addresses. # Test: Search for the `useInfo` hook implementation. Expect: `decimal` and `token` are returned correctly. ast-grep --lang typescript --pattern $'function useInfo($_) { $$$ return { api, decimal, token, $$$ } }'Length of output: 109
Script:
#!/bin/bash # Search for the implementation of the `useInfo` hook in the codebase. ast-grep --lang typescript --pattern 'function useInfo($$$) { $$$ }' --json # If the above does not yield results, search for any function named `useInfo`. rg 'function useInfo' -A 10Length of output: 1053
Script:
#!/bin/bash # Extract the full return statement of the `useInfo` function to verify the inclusion of `decimal` and `token`. rg 'return useMemo' -A 10 packages/extension-polkagate/src/hooks/useInfo.tsLength of output: 339
38-38
: Consider edge cases for unlocking logic.The
useTimeToUnlock
hook is used to manage unlocking logic. Consider edge cases wherereferendaLocks
might be empty or undefined, and ensure these are handled gracefully.Verification successful
Edge cases for unlocking logic are handled.
The
useTimeToUnlock
function addresses edge cases wherereferendaLocks
might benull
, undefined, or empty, ensuring graceful handling of these scenarios by setting appropriate states.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that `useTimeToUnlock` handles edge cases where `referendaLocks` is empty or undefined. # Test: Search for the `useTimeToUnlock` hook implementation. Expect: Proper handling of empty or undefined `referendaLocks`. ast-grep --lang typescript --pattern $'function useTimeToUnlock($_, referendaLocks, $$$) { if (referendaLocks === undefined || referendaLocks.length === 0) { $$$ } $$$ }'Length of output: 181
Script:
#!/bin/bash # Description: Locate the implementation of the `useTimeToUnlock` hook to verify its handling of edge cases. # Search for the implementation of `useTimeToUnlock` in the codebase. rg 'function useTimeToUnlock' -A 20Length of output: 2259
Script:
#!/bin/bash # Description: Extract the full implementation of the `useTimeToUnlock` function to analyze its logic. # Search for the full implementation of `useTimeToUnlock` in the codebase. rg 'export default function useTimeToUnlock' -A 50 packages/extension-polkagate/src/hooks/useTimeToUnlock.tsxLength of output: 1765
packages/extension-polkagate/src/hooks/index.ts (1)
99-99
: New hook export:useTimeToUnlock
.The addition of
useTimeToUnlock
to the exports is appropriate, expanding the module's functionality. Ensure that this hook is implemented correctly and used consistently across the codebase.packages/extension-polkagate/src/popup/account/index.tsx (1)
242-249
: Simplify conditional rendering logic.The use of logical AND (
&&
) for conditional rendering improves readability. Ensure that the conditions for displaying staking labels are correctly evaluated.
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- packages/extension-polkagate/src/hooks/useTimeToUnlock.tsx (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- packages/extension-polkagate/src/hooks/useTimeToUnlock.tsx
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- packages/extension-polkagate/src/hooks/index.ts (1 hunks)
Files skipped from review due to trivial changes (1)
- packages/extension-polkagate/src/hooks/index.ts
closes #1071
I have utilized the logic mentioned here: paritytech/polkadot-sdk#1833 (comment)
like:
and the result:
Summary by CodeRabbit