-
Notifications
You must be signed in to change notification settings - Fork 635
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
Wallet Groups #6314
Open
greg-schrammel
wants to merge
16
commits into
develop
Choose a base branch
from
gregs/app-1382-prompt-user-to-choose-wallet-group-when-creating-a-wallet
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+248
−104
Open
Wallet Groups #6314
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
93bca72
wallet groups
greg-schrammel a745d29
a
greg-schrammel d310567
ops
greg-schrammel d1d29d1
ens
greg-schrammel e926d1d
Merge branch 'develop' into gregs/app-1382-prompt-user-to-choose-wall…
greg-schrammel fda4500
design
greg-schrammel 6a8faca
a
greg-schrammel f19143a
sheet
greg-schrammel 674818c
Merge remote-tracking branch 'origin/develop' into gregs/app-1382-pro…
greg-schrammel 910eb9e
android route
greg-schrammel 53f7784
swipe nav & backups v2
greg-schrammel ddd8a7c
better scroll
greg-schrammel 0986506
revert
greg-schrammel 5d3cd11
fix styles
greg-schrammel dac52b3
fix dark mode
greg-schrammel 4d7c5b2
👍
greg-schrammel 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The other screens of the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes good call |
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,225 @@ | ||
import React from 'react'; | ||
import { Box, Separator, Text, useForegroundColor } from '@/design-system'; | ||
import { View, Text as NativeText, ViewStyle } from 'react-native'; | ||
import chroma from 'chroma-js'; | ||
import { useInitializeWallet, useWallets } from '@/hooks'; | ||
import { useDispatch } from 'react-redux'; | ||
import Routes from '@/navigation/routesNames'; | ||
import { useNavigation } from './Navigation'; | ||
import WalletTypes from '@/helpers/walletTypes'; | ||
import { logger, RainbowError } from '@/logger'; | ||
import { createAccountForWallet, walletsLoadState } from '@/redux/wallets'; | ||
import { createWallet, RainbowAccount, RainbowWallet } from '@/model/wallet'; | ||
import { ButtonPressAnimation } from '@/components/animations'; | ||
import { abbreviateEnsForDisplay, formatAddressForDisplay } from '@/utils/abbreviations'; | ||
import { ImgixImage } from '@/components/images'; | ||
import { useTheme } from '@/theme'; | ||
import { removeFirstEmojiFromString, returnStringFirstEmoji } from '@/helpers/emojiHandler'; | ||
import { profileUtils } from '@/utils'; | ||
import * as i18n from '@/languages'; | ||
import showWalletErrorAlert from '@/helpers/support'; | ||
import { ScrollView } from 'react-native-gesture-handler'; | ||
import CreateNewWalletGroupIcon from '@/assets/CreateNewWalletGroup.png'; | ||
|
||
function NewWalletGroup({ numWalletGroups }: { numWalletGroups: number }) { | ||
const blue = useForegroundColor('blue'); | ||
|
||
const { navigate } = useNavigation(); | ||
const dispatch = useDispatch(); | ||
const initializeWallet = useInitializeWallet(); | ||
|
||
const onNewWalletGroup = () => { | ||
navigate(Routes.MODAL_SCREEN, { | ||
actionType: 'Create', | ||
numWalletGroups, | ||
onCloseModal: async (args: { name: string; color: number }) => { | ||
if (!args) return; | ||
try { | ||
const { name, color } = args; | ||
await createWallet({ color, name }); | ||
await dispatch(walletsLoadState()); | ||
// @ts-expect-error - needs refactor to object params | ||
await initializeWallet(); | ||
navigate(Routes.WALLET_SCREEN, {}, true); | ||
} catch (error) { | ||
logger.error(new RainbowError('[AddWalletSheet]: Error while trying to add account'), { error }); | ||
} | ||
}, | ||
profile: { color: null, name: `` }, | ||
type: 'new_wallet_group', | ||
}); | ||
}; | ||
|
||
return ( | ||
<ButtonPressAnimation | ||
onPress={onNewWalletGroup} | ||
scaleTo={0.95} | ||
style={{ | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
gap: 10, | ||
paddingHorizontal: 12, | ||
paddingVertical: 10, | ||
borderRadius: 30, | ||
height: 60, | ||
width: '100%', | ||
backgroundColor: chroma(blue).alpha(0.05).hex(), | ||
borderWidth: 1, | ||
borderColor: chroma(blue).alpha(0.06).hex(), | ||
}} | ||
> | ||
<ImgixImage style={{ height: 36, width: 36, borderRadius: 18 }} source={CreateNewWalletGroupIcon} /> | ||
<View style={{ gap: 10 }}> | ||
<Text color="blue" size="17pt" weight="heavy"> | ||
{i18n.t(i18n.l.wallet.new.new_wallet_group.title)} | ||
</Text> | ||
<Text color="labelQuaternary" size="13pt" weight="bold"> | ||
{i18n.t(i18n.l.wallet.new.new_wallet_group.description)} | ||
</Text> | ||
</View> | ||
</ButtonPressAnimation> | ||
); | ||
} | ||
|
||
function AccountAvatar({ account, size }: { account: RainbowAccount; size: number }) { | ||
const { colors } = useTheme(); | ||
|
||
if (account.image) { | ||
return <ImgixImage source={{ uri: account.image }} style={{ height: size, width: size, borderRadius: size / 2 }} />; | ||
} | ||
|
||
const backgroundColor = colors.avatarBackgrounds[account.color]; | ||
const emoji = returnStringFirstEmoji(account.label) || profileUtils.addressHashedEmoji(account.address); | ||
|
||
return ( | ||
<View | ||
style={[ | ||
{ backgroundColor, height: size, width: size, borderRadius: size / 2 }, | ||
{ alignItems: 'center', justifyContent: 'center' }, | ||
]} | ||
> | ||
<NativeText style={{ fontSize: size / 2, textAlign: 'center' }}>{emoji}</NativeText> | ||
</View> | ||
); | ||
} | ||
|
||
function WalletGroup({ wallet }: { wallet: RainbowWallet }) { | ||
const separatorSecondary = useForegroundColor('separatorSecondary'); | ||
|
||
const accounts = wallet.addresses; | ||
|
||
const { navigate } = useNavigation(); | ||
const dispatch = useDispatch(); | ||
const initializeWallet = useInitializeWallet(); | ||
|
||
const onAddToGroup = () => { | ||
navigate(Routes.MODAL_SCREEN, { | ||
actionType: 'Create', | ||
asset: [], | ||
isNewProfile: true, | ||
onCloseModal: async (args: { name: string; color: number }) => { | ||
if (!args) return; | ||
try { | ||
const { name, color } = args; | ||
if (wallet.damaged) throw new Error('Wallet is damaged'); | ||
await dispatch(createAccountForWallet(wallet.id, color, name)); | ||
// @ts-expect-error - needs refactor to object params | ||
await initializeWallet(); | ||
navigate(Routes.WALLET_SCREEN, {}, true); | ||
} catch (e) { | ||
logger.error(new RainbowError('[AddWalletSheet]: Error while trying to add account'), { error: e }); | ||
showWalletErrorAlert(); | ||
} | ||
}, | ||
profile: { color: null, name: `` }, | ||
type: 'wallet_profile', | ||
}); | ||
}; | ||
|
||
return ( | ||
<ButtonPressAnimation onPress={onAddToGroup} scaleTo={0.95} style={{ flexDirection: 'row', alignItems: 'center', gap: 10 }}> | ||
<View | ||
style={[ | ||
{ height: 40, width: 40, gap: 2, padding: 5 }, | ||
{ borderRadius: 10, backgroundColor: separatorSecondary }, | ||
{ flexWrap: 'wrap', flexDirection: 'row' }, | ||
]} | ||
> | ||
{accounts.slice(0, 4).map(account => ( | ||
<AccountAvatar key={account.address} account={account} size={14} /> | ||
))} | ||
</View> | ||
<View style={{ gap: 8 }}> | ||
<Text color="label" size="15pt" weight="semibold"> | ||
{removeFirstEmojiFromString(wallet.name)} | ||
</Text> | ||
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 5 }}> | ||
<Text color="labelQuaternary" size="13pt" weight="bold"> | ||
{abbreviateEnsForDisplay(accounts[0].ens) || formatAddressForDisplay(accounts[0].address, 4, 4)} | ||
</Text> | ||
{accounts.length > 1 && ( | ||
<View | ||
style={[ | ||
{ height: 16, paddingHorizontal: 3.5, justifyContent: 'center', marginVertical: -2 }, | ||
{ borderColor: chroma(separatorSecondary).alpha(0.04).hex(), borderWidth: 1, borderRadius: 6 }, | ||
{ backgroundColor: separatorSecondary }, | ||
]} | ||
> | ||
<Text color="labelQuaternary" size="11pt" weight="bold"> | ||
{`+${accounts.length - 1}`} | ||
</Text> | ||
</View> | ||
)} | ||
</View> | ||
</View> | ||
</ButtonPressAnimation> | ||
); | ||
} | ||
|
||
export function ChooseWalletGroup() { | ||
const { goBack } = useNavigation(); | ||
const { wallets } = useWallets(); | ||
|
||
if (!wallets) { | ||
showWalletErrorAlert(); | ||
return; | ||
} | ||
|
||
const groups = Object.values(wallets).filter(wallet => wallet.type === WalletTypes.mnemonic); | ||
|
||
return ( | ||
<Box background="surfaceSecondary" style={{ width: '100%', gap: 20, alignItems: 'center', paddingBottom: 64 }}> | ||
<View style={{ paddingHorizontal: 24, gap: 20, width: '100%' }}> | ||
<View style={{ paddingTop: 24, paddingBottom: 12 }}> | ||
<ButtonPressAnimation scaleTo={0.9} onPress={goBack} hitSlop={64} style={{ width: 20, height: 20 }}> | ||
<Text color="blue" size="22pt" weight="bold"> | ||
| ||
</Text> | ||
</ButtonPressAnimation> | ||
</View> | ||
<Text color="label" size="22pt" weight="heavy" align="center"> | ||
{i18n.t(i18n.l.wallet.new.choose_wallet_group.title)} | ||
</Text> | ||
<Text color="labelQuaternary" size="15pt" weight="semibold" align="center"> | ||
{i18n.t(i18n.l.wallet.new.choose_wallet_group.description)} | ||
</Text> | ||
|
||
<View style={{ width: '100%' }}> | ||
<Separator color={'separatorTertiary'} /> | ||
</View> | ||
</View> | ||
|
||
<ScrollView | ||
style={{ width: '100%', marginTop: -20 }} | ||
contentContainerStyle={{ gap: 16, paddingTop: 20, paddingHorizontal: 24, paddingBottom: 200 }} | ||
> | ||
<NewWalletGroup numWalletGroups={groups.length} /> | ||
<View style={{ paddingHorizontal: 12, gap: 16 }}> | ||
{groups.map(wallet => ( | ||
<WalletGroup key={wallet.id} wallet={wallet} /> | ||
))} | ||
</View> | ||
</ScrollView> | ||
</Box> | ||
); | ||
} |
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 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
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.
Any reason this was needed over the existing CreateNewWallet.png?
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.
that one has a builtin shadow