-
Notifications
You must be signed in to change notification settings - Fork 11
CP-12312: display platform accounts #3308
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
Closed
Closed
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
648ea5b
add logger
ruijialin-avalabs 5be0d57
add enable networks without xp selector
ruijialin-avalabs 1c3c88c
show platform accounts
ruijialin-avalabs 100c162
update selectors
ruijialin-avalabs f6b4b91
make wallet title 2 line
ruijialin-avalabs ced604a
update accoutn id to include walletId
ruijialin-avalabs 6a09012
update platform account addresses for seedless
ruijialin-avalabs 7c24469
Merge branch 'main' into cp-12312
ruijialin-avalabs 1b1c2bb
make selectPlatformAccounts selector private
ruijialin-avalabs 05f2703
remove unnecessary filter
ruijialin-avalabs 9254493
fix import
ruijialin-avalabs b12b9fb
fix test
ruijialin-avalabs 838f00c
dont show platform accounts in recent account list
ruijialin-avalabs 349141a
Merge branch 'main' into cp-12312
ruijialin-avalabs 1e7b0f4
fix test
ruijialin-avalabs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
54 changes: 54 additions & 0 deletions
54
packages/core-mobile/app/new/common/contexts/useBalanceForXpAccunt.ts
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { useCallback, useState, useEffect } from 'react' | ||
| import { useDispatch, useSelector } from 'react-redux' | ||
| import { | ||
| fetchXpBalancesForWallet, | ||
| QueryStatus, | ||
| selectBalanceTotalInCurrencyForXpNetwork, | ||
| selectIsXpBalanceLoadedForWallet, | ||
| selectXpBalanceStatus | ||
| } from 'store/balance' | ||
| import { XpNetworkVMType } from 'store/network' | ||
| import { selectWalletById } from 'store/wallet/slice' | ||
|
|
||
| export const useBalanceFoXpAccount = ( | ||
| walletId: string, | ||
| networkType: XpNetworkVMType | ||
| ): { | ||
| isBalanceLoaded: boolean | ||
| fetchBalance: () => void | ||
| isFetchingBalance: boolean | ||
| balance: number | ||
| } => { | ||
| const dispatch = useDispatch() | ||
| const wallet = useSelector(selectWalletById(walletId)) | ||
| const xpBalanceStatus = useSelector(selectXpBalanceStatus) | ||
| const isBalanceLoading = xpBalanceStatus !== QueryStatus.IDLE | ||
| const [isFetchingBalance, setIsFetchingBalance] = useState(true) | ||
| const accountBalance = useSelector( | ||
| selectBalanceTotalInCurrencyForXpNetwork(walletId, networkType) | ||
| ) | ||
|
|
||
| const isBalanceLoaded = useSelector( | ||
| selectIsXpBalanceLoadedForWallet(walletId, networkType) | ||
| ) | ||
|
|
||
| const fetchBalance = useCallback(() => { | ||
| if (wallet) { | ||
| dispatch(fetchXpBalancesForWallet({ wallet })) | ||
| setIsFetchingBalance(true) | ||
| } | ||
| }, [wallet, dispatch]) | ||
|
|
||
| useEffect(() => { | ||
| if (!isBalanceLoading && isFetchingBalance) { | ||
| setIsFetchingBalance(false) | ||
| } | ||
| }, [isFetchingBalance, isBalanceLoading, setIsFetchingBalance]) | ||
|
|
||
| return { | ||
| balance: accountBalance, | ||
| fetchBalance, | ||
| isFetchingBalance, | ||
| isBalanceLoaded | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
84 changes: 84 additions & 0 deletions
84
packages/core-mobile/app/new/features/accountSettings/components/AccountBalance.tsx
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import React, { useCallback, useMemo } from 'react' | ||
| import { | ||
| ActivityIndicator, | ||
| alpha, | ||
| AnimatedBalance, | ||
| Icons, | ||
| Pressable, | ||
| SCREEN_WIDTH, | ||
| useTheme | ||
| } from '@avalabs/k2-alpine' | ||
| import { useSelector } from 'react-redux' | ||
| import { selectIsPrivacyModeEnabled } from 'store/settings/securityPrivacy' | ||
| import { useBalanceForAccount } from 'new/common/contexts/useBalanceForAccount' | ||
| import { useFormatCurrency } from 'new/common/hooks/useFormatCurrency' | ||
| import { UNKNOWN_AMOUNT } from 'consts/amount' | ||
| import { HiddenBalanceText } from 'common/components/HiddenBalanceText' | ||
|
|
||
| export const AccountBalance = ({ | ||
| isActive, | ||
| accountId | ||
| }: { | ||
| isActive: boolean | ||
| accountId: string | ||
| }): React.JSX.Element => { | ||
| const isPrivacyModeEnabled = useSelector(selectIsPrivacyModeEnabled) | ||
| const { | ||
| theme: { colors } | ||
| } = useTheme() | ||
| const { | ||
| balance: accountBalance, | ||
| fetchBalance, | ||
| isFetchingBalance, | ||
| isBalanceLoaded | ||
| } = useBalanceForAccount(accountId) | ||
| const { formatCurrency } = useFormatCurrency() | ||
|
|
||
| const balance = useMemo(() => { | ||
| return accountBalance === 0 | ||
| ? formatCurrency({ amount: 0 }).replace(/[\d.,]+/g, UNKNOWN_AMOUNT) | ||
| : formatCurrency({ amount: accountBalance }) | ||
| }, [accountBalance, formatCurrency]) | ||
|
|
||
| const renderMaskView = useCallback(() => { | ||
| return ( | ||
| <HiddenBalanceText | ||
| variant={'heading6'} | ||
| sx={{ | ||
| color: isActive | ||
| ? colors.$textPrimary | ||
| : alpha(colors.$textPrimary, 0.6), | ||
| lineHeight: 18 | ||
| }} | ||
| /> | ||
| ) | ||
| }, [colors.$textPrimary, isActive]) | ||
|
|
||
| if (isFetchingBalance) { | ||
| return <ActivityIndicator size="small" sx={{ marginRight: 4 }} /> | ||
| } | ||
|
|
||
| if (!isBalanceLoaded) { | ||
| return ( | ||
| <Pressable onPress={fetchBalance}> | ||
| <Icons.Custom.BalanceRefresh color={colors.$textPrimary} /> | ||
| </Pressable> | ||
| ) | ||
| } | ||
|
|
||
| return ( | ||
| <AnimatedBalance | ||
| variant="body1" | ||
| balance={balance} | ||
| shouldMask={isPrivacyModeEnabled} | ||
| balanceSx={{ | ||
| color: isActive ? colors.$textPrimary : alpha(colors.$textPrimary, 0.6), | ||
| lineHeight: 18, | ||
| width: SCREEN_WIDTH * 0.3, | ||
| textAlign: 'right' | ||
| }} | ||
| renderMaskView={renderMaskView} | ||
| shouldAnimate={false} | ||
| /> | ||
| ) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
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.
this will be adjusted in future platform account send flow ticket.