-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: go to account from accountsheet, add real balances and address ref
- Loading branch information
1 parent
8d0b3dd
commit 5abb340
Showing
14 changed files
with
159 additions
and
111 deletions.
There are no files selected for viewing
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
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
This file was deleted.
Oops, something went wrong.
File renamed without changes.
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
76 changes: 76 additions & 0 deletions
76
apps/mobile/src/features/accounts/account-selector/account-selector-sheet.layout.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { RefObject, useRef } from 'react'; | ||
import { ScrollView } from 'react-native'; | ||
import { useSharedValue } from 'react-native-reanimated'; | ||
|
||
import { AvatarIcon } from '@/components/avatar-icon'; | ||
import { Draggable } from '@/components/draggable'; | ||
import { Account } from '@/store/accounts/accounts'; | ||
import { useSettings } from '@/store/settings/settings'; | ||
import { defaultIconTestId } from '@/utils/testing-utils'; | ||
import { useTheme } from '@shopify/restyle'; | ||
|
||
import { Box, Sheet, SheetRef, Theme } from '@leather.io/ui/native'; | ||
|
||
import { AccountAddress } from '../components/account-address'; | ||
import { AccountBalance } from '../components/account-balance'; | ||
import { AccountCard } from '../components/account-card'; | ||
|
||
interface AccountSelectorSheetLayoutProps { | ||
accounts: Account[]; | ||
onAccountPress: (accountId: string) => void; | ||
swapAccountIndexes: (from: number, to: number) => void; | ||
sheetRef: RefObject<SheetRef>; | ||
} | ||
|
||
export function AccountSelectorSheetLayout({ | ||
accounts, | ||
onAccountPress, | ||
swapAccountIndexes, | ||
sheetRef, | ||
}: AccountSelectorSheetLayoutProps) { | ||
const scrollViewRef = useRef<ScrollView>(null); | ||
const placeholderIdx = useSharedValue<null | number>(null); | ||
const direction = useSharedValue<'down' | 'up'>('down'); | ||
const theme = useTheme<Theme>(); | ||
const { themeDerivedFromThemePreference } = useSettings(); | ||
|
||
return ( | ||
<Sheet isScrollView ref={sheetRef} themeVariant={themeDerivedFromThemePreference}> | ||
<Box p="5" gap="5"> | ||
{accounts.map((account, idx) => ( | ||
<Draggable | ||
idx={idx} | ||
direction={direction} | ||
scrollViewRef={scrollViewRef} | ||
placeholderIdx={placeholderIdx} | ||
cardsLength={accounts.length} | ||
key={account.id} | ||
cardId={account.id} | ||
onCardPress={() => onAccountPress(account.id)} | ||
swapCardIndexes={swapAccountIndexes} | ||
> | ||
<AccountCard | ||
address={ | ||
<AccountAddress | ||
accountIndex={account.accountIndex} | ||
fingerprint={account.fingerprint} | ||
/> | ||
} | ||
balance={ | ||
<AccountBalance | ||
accountIndex={account.accountIndex} | ||
fingerprint={account.fingerprint} | ||
/> | ||
} | ||
icon={ | ||
<AvatarIcon color={theme.colors['ink.background-primary']} icon={account.icon} /> | ||
} | ||
name={account.name} | ||
iconTestID={defaultIconTestId(account.icon)} | ||
/> | ||
</Draggable> | ||
))} | ||
</Box> | ||
</Sheet> | ||
); | ||
} |
62 changes: 62 additions & 0 deletions
62
apps/mobile/src/features/accounts/account-selector/account-selector-sheet.tsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { RefObject, useCallback, useMemo } from 'react'; | ||
|
||
import { AppRoutes } from '@/routes'; | ||
import { useAccounts } from '@/store/accounts/accounts.read'; | ||
import { userUpdatesAccountOrder } from '@/store/accounts/accounts.write'; | ||
import { useAppDispatch } from '@/store/utils'; | ||
import { useRouter } from 'expo-router'; | ||
|
||
import { SheetRef } from '@leather.io/ui/native'; | ||
|
||
import { AccountSelectorSheetLayout } from './account-selector-sheet.layout'; | ||
|
||
export function AccountSelectorSheet({ sheetRef }: { sheetRef: RefObject<SheetRef> }) { | ||
const accounts = useAccounts().list; | ||
const router = useRouter(); | ||
const dispatch = useAppDispatch(); | ||
const checkIdxWithinBounds = useCallback( | ||
(id: number) => { | ||
return id >= 0 && id < accounts.length; | ||
}, | ||
[accounts.length] | ||
); | ||
|
||
const accountIds = useMemo(() => accounts.map(acc => acc.id), [accounts]); | ||
const swapAccountIndexes = useCallback( | ||
(idx1: number | null, idx2: number | null) => { | ||
if ( | ||
idx1 === null || | ||
idx2 === null || | ||
!checkIdxWithinBounds(idx1) || | ||
!checkIdxWithinBounds(idx2) || | ||
!accountIds[idx1] || | ||
!accountIds[idx2] | ||
) | ||
return; | ||
const temp = accountIds[idx1]; | ||
accountIds[idx1] = accountIds[idx2]; | ||
accountIds[idx2] = temp; | ||
dispatch(userUpdatesAccountOrder({ accountIds })); | ||
}, | ||
[accountIds, checkIdxWithinBounds, dispatch] | ||
); | ||
const onAccountPress = useCallback( | ||
(accountId: string) => { | ||
sheetRef.current?.close(); | ||
router.navigate({ | ||
pathname: AppRoutes.Account, | ||
params: { accountId }, | ||
}); | ||
}, | ||
[router, sheetRef] | ||
); | ||
|
||
return ( | ||
<AccountSelectorSheetLayout | ||
accounts={accounts} | ||
onAccountPress={onAccountPress} | ||
swapAccountIndexes={swapAccountIndexes} | ||
sheetRef={sheetRef} | ||
/> | ||
); | ||
} |
File renamed without changes.
File renamed without changes.
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
6 changes: 3 additions & 3 deletions
6
apps/mobile/src/features/approver/components/approver-account-card.tsx
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
2 changes: 1 addition & 1 deletion
2
apps/mobile/src/features/receive/receive-sheets/select-account.tsx
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
2 changes: 1 addition & 1 deletion
2
apps/mobile/src/features/send/send-sheets/select-account-sheet.tsx
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
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