Skip to content
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

fix: setup of pfp with blockie on context #242

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/home/receive/ReceiveScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { Theme } from 'src/shared/types';
import { useThemedStyle } from 'src/shared/hooks/useThemedStyle';
import { abbreviateAddress } from 'src/shared/services/quais';
import { useSnackBar } from 'src/shared/context/snackBarContext';
import { useWalletContext } from 'src/shared/context/walletContext';

import ShareControl from './ShareControl';

Expand All @@ -34,7 +35,8 @@ export const ReceiveScreen = () => {
const { showSnackBar } = useSnackBar();
const isDarkMode = useColorScheme() === 'dark';
const navigation = useNavigation<RootStackNavigationProps<'Main'>>();
const profilePicture = useProfilePicture();
const { profilePicture } = useWalletContext(); // get bare profile picture state
useProfilePicture(); // fetch profilePicture
juanmanso marked this conversation as resolved.
Show resolved Hide resolved
const username = useUsername();
const wallet = useWallet();

Expand Down
2 changes: 1 addition & 1 deletion src/onboarding/screens/SetupNameAndPFPScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const SetupNameAndPFPScreen: React.FC<
if (!profilePicture) {
await storeItem({
key: keychainKeys.profilePicture,
value: walletBlockie,
value: indexedZones[currentWalletIndex],
});
}
navigation.navigate('SetupLocation');
Expand Down
7 changes: 6 additions & 1 deletion src/shared/components/QuaiPayCamera/QuaiPayCamera.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
} from 'src/shared/utils/seedPhrase';

import { ScannerType } from './QuaiPayCamera.types';
import { Zone } from 'src/shared/types';
import makeBlockie from 'ethereum-blockies-base64';

interface HookOutput {
frameProcessor: (frame: Frame) => void;
Expand Down Expand Up @@ -50,7 +52,10 @@ const useSendAmountScannerCamera = () => {
params: {
amount: amount || 0,
receiverAddress: address,
receiverPFP: profilePicture,
// TODO: replace address to generate blockie with walletObject[zone] when setup
receiverPFP: Zone?.[profilePicture as keyof typeof Zone]
? makeBlockie(address)
: profilePicture,
receiverUsername: username,
sender: sender!,
},
Expand Down
13 changes: 11 additions & 2 deletions src/shared/hooks/useProfilePicture.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { useWalletContext } from 'src/shared/context/walletContext';
import { useEffect } from 'react';
import makeBlockie from 'ethereum-blockies-base64';

import { useWalletContext } from 'src/shared/context/walletContext';
import { Zone } from '../types';

export const useProfilePicture = (): string | undefined => {
const { profilePicture, getProfilePicture } = useWalletContext();
Expand All @@ -8,5 +11,11 @@ export const useProfilePicture = (): string | undefined => {
getProfilePicture();
}
}, [profilePicture]);
return profilePicture;
return profilePicture && checkProfilePictureStringIsZone(profilePicture)
? makeBlockie(profilePicture)
: profilePicture;
};

// Check by indexing Zone enum. If valid, it will be true
const checkProfilePictureStringIsZone = (s: string) =>
!!Zone?.[s as keyof typeof Zone];
juanmanso marked this conversation as resolved.
Show resolved Hide resolved