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

add ledger #5233

Merged
merged 9 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
12 changes: 5 additions & 7 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,11 @@ class OldApp extends Component {
{this.state.initialRoute && (
<RemotePromoSheetProvider isWalletReady={this.props.walletReady}>
<InitialRouteContext.Provider value={this.state.initialRoute}>
<PointsProfileProvider>
<RoutesComponent
onReady={this.handleSentryNavigationIntegration}
ref={this.handleNavigatorRef}
/>
<PortalConsumer />
</PointsProfileProvider>
<RoutesComponent
onReady={this.handleSentryNavigationIntegration}
ref={this.handleNavigatorRef}
/>
<PortalConsumer />
</InitialRouteContext.Provider>
</RemotePromoSheetProvider>
)}
Expand Down
3 changes: 3 additions & 0 deletions src/handlers/LedgerSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,17 @@ export class LedgerSigner extends Signer {

async signMessage(message: Bytes | string): Promise<string> {
if (typeof message === 'string') {
console.log('toUtf8Bytes');
skylarbarrera marked this conversation as resolved.
Show resolved Hide resolved
message = toUtf8Bytes(message);
}

const messageHex = hexlify(message).substring(2);
console.log({ messageHex });
skylarbarrera marked this conversation as resolved.
Show resolved Hide resolved

const sig = await this._retry(eth =>
eth.signPersonalMessage(this.path!, messageHex)
);
console.log('post signatureeee');
skylarbarrera marked this conversation as resolved.
Show resolved Hide resolved
sig.r = '0x' + sig.r;
sig.s = '0x' + sig.s;
return joinSignature(sig);
Expand Down
2 changes: 2 additions & 0 deletions src/model/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,9 @@ export const signPersonalMessage = async (
const wallet =
existingWallet || (await loadWallet(undefined, true, provider));
// have to check inverse or we trigger unwanted BT permissions requests
console.log(typeof wallet);
skylarbarrera marked this conversation as resolved.
Show resolved Hide resolved
if (!(wallet instanceof Wallet)) {
console.log('we got a hardware wallet ');
skylarbarrera marked this conversation as resolved.
Show resolved Hide resolved
isHardwareWallet = true;
}
try {
Expand Down
5 changes: 4 additions & 1 deletion src/navigation/Routes.android.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import { MintsSheet } from '@/screens/MintsSheet/MintsSheet';
import { SignTransactionSheet } from '@/screens/SignTransactionSheet';
import { RemotePromoSheet } from '@/components/remote-promo-sheet/RemotePromoSheet';
import { ConsoleSheet } from '@/screens/points/ConsoleSheet';
import { PointsProfileProvider } from '@/screens/points/contexts/PointsProfileContext';

const Stack = createStackNavigator();
const OuterStack = createStackNavigator();
Expand Down Expand Up @@ -431,7 +432,9 @@ const AppContainerWithAnalytics = React.forwardRef(
// @ts-ignore
ref={ref}
>
<AuthNavigator />
<PointsProfileProvider>
<AuthNavigator />
</PointsProfileProvider>
</NavigationContainer>
)
);
Expand Down
5 changes: 4 additions & 1 deletion src/navigation/Routes.ios.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ import MintSheet from '@/screens/mints/MintSheet';
import { MintsSheet } from '@/screens/MintsSheet/MintsSheet';
import { RemotePromoSheet } from '@/components/remote-promo-sheet/RemotePromoSheet';
import { ConsoleSheet } from '@/screens/points/ConsoleSheet';
import { PointsProfileProvider } from '@/screens/points/contexts/PointsProfileContext';

type StackNavigatorParams = {
[Routes.SEND_SHEET]: unknown;
Expand Down Expand Up @@ -475,7 +476,9 @@ const AppContainerWithAnalytics = React.forwardRef(
// @ts-ignore
ref={ref}
>
<NativeStackNavigator />
<PointsProfileProvider>
<NativeStackNavigator />
</PointsProfileProvider>
</NavigationContainer>
)
);
Expand Down
19 changes: 16 additions & 3 deletions src/screens/points/contexts/PointsProfileContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import React, {
useState,
} from 'react';
import { noop } from 'lodash';

import Routes from '@/navigation/routesNames';
import { pointsQueryKey } from '@/resources/points';
import * as i18n from '@/languages';
import { POINTS_TWEET_INTENT_ID, RainbowPointsFlowSteps } from '../constants';
Expand All @@ -20,10 +20,11 @@ import { WrappedAlert as Alert } from '@/helpers/alert';

import { usePointsTweetIntentQuery } from '@/resources/pointsTweetIntent/pointsTweetIntentQuery';
import { metadataPOSTClient } from '@/graphql';
import { useAccountProfile } from '@/hooks';
import { useAccountProfile, useWallets } from '@/hooks';
import { signPersonalMessage } from '@/model/wallet';
import { RainbowError, logger } from '@/logger';
import { queryClient } from '@/react-query';
import { useNavigation } from '@/navigation';

type PointsProfileContext = {
step: RainbowPointsFlowSteps;
Expand Down Expand Up @@ -94,6 +95,8 @@ export const PointsProfileProvider = ({
children: React.ReactNode;
}) => {
const { accountAddress } = useAccountProfile();
const { isHardwareWallet } = useWallets();
const { navigate } = useNavigation();

const [step, setStep] = useState<RainbowPointsFlowSteps>(
RainbowPointsFlowSteps.Initialize
Expand Down Expand Up @@ -142,7 +145,9 @@ export const PointsProfileProvider = ({

const challenge = challengeResponse?.pointsOnboardChallenge;
if (challenge) {
console.log('signing message');
skylarbarrera marked this conversation as resolved.
Show resolved Hide resolved
const signatureResponse = await signPersonalMessage(challenge);
console.log('!!!!!!!: ', { signatureResponse });
skylarbarrera marked this conversation as resolved.
Show resolved Hide resolved
signature = signatureResponse?.result;
if (signature) {
points = await metadataPOSTClient.onboardPoints({
Expand Down Expand Up @@ -179,6 +184,14 @@ export const PointsProfileProvider = ({
}
}, [accountAddress, referralCode]);

const signInHandler = useCallback(async () => {
if (isHardwareWallet) {
navigate(Routes.HARDWARE_WALLET_TX_NAVIGATOR, { submit: signIn });
} else {
signIn();
}
}, [isHardwareWallet, navigate, signIn]);

usePointsTweetIntentQuery(
{
id: POINTS_TWEET_INTENT_ID,
Expand Down Expand Up @@ -247,7 +260,7 @@ export const PointsProfileProvider = ({
setShareBonusPoints,

// functions
signIn,
signIn: signInHandler,

// helpers
rainbowSwaps,
Expand Down
Loading