Skip to content

Commit

Permalink
used new useAuth hook for logIn (#1868)
Browse files Browse the repository at this point in the history
  • Loading branch information
seeden committed Jun 23, 2023
1 parent 907b921 commit 60bfd2d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
11 changes: 4 additions & 7 deletions packages/gui/src/hooks/useWalletConnectCommand.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import api, { store, useGetLoggedInFingerprintQuery, useLogInMutation } from '@chia-network/api-react';
import { useOpenDialog } from '@chia-network/core';
import api, { store, useGetLoggedInFingerprintQuery } from '@chia-network/api-react';
import { useOpenDialog, useAuth } from '@chia-network/core';
import { Trans } from '@lingui/macro';
import debug from 'debug';
import React, { type ReactNode } from 'react';
Expand Down Expand Up @@ -71,7 +71,7 @@ function parseNotification(
export default function useWalletConnectCommand(options: UseWalletConnectCommandOptions) {
const { onNotification } = options;
const openDialog = useOpenDialog();
const [logIn] = useLogInMutation();
const { logIn } = useAuth();
const { data: currentFingerprint, isLoading: isLoadingLoggedInFingerprint } = useGetLoggedInFingerprintQuery();
const { getPairBySession } = useWalletConnectPairs();

Expand Down Expand Up @@ -197,10 +197,7 @@ export default function useWalletConnectCommand(options: UseWalletConnectCommand
// auto login before execute command
if (isDifferentFingerprint && allowConfirmationFingerprintChange) {
log('Changing fingerprint', fingerprint);
await logIn({
fingerprint,
type: 'skip',
}).unwrap();
await logIn(fingerprint);
}

// wait for sync
Expand Down
10 changes: 4 additions & 6 deletions packages/wallets/src/components/WalletAdd.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useGenerateMnemonicMutation, useAddPrivateKeyMutation, useLogInMutation } from '@chia-network/api-react';
import { ButtonLoading, Form, TextField, Flex, Loading, Logo, useShowError } from '@chia-network/core';
import { useGenerateMnemonicMutation, useAddPrivateKeyMutation } from '@chia-network/api-react';
import { ButtonLoading, Form, TextField, Flex, Loading, Logo, useAuth, useShowError } from '@chia-network/core';
import { Trans } from '@lingui/macro';
import { TextField as TextFieldMaterial, Typography, Grid, Container } from '@mui/material';
import React from 'react';
Expand All @@ -15,7 +15,7 @@ export default function WalletAdd() {
const navigate = useNavigate();
const [generateMnemonic, { data: words, isLoading }] = useGenerateMnemonicMutation();
const [addPrivateKey] = useAddPrivateKeyMutation();
const [logIn] = useLogInMutation();
const { logIn } = useAuth();
const methods = useForm<FormData>({
defaultValues: {
label: '',
Expand Down Expand Up @@ -45,9 +45,7 @@ export default function WalletAdd() {
...(label && { label: label.trim() }), // omit `label` if label is undefined/empty. backend returns an error if label is set and undefined/empty
}).unwrap();

await logIn({
fingerprint,
}).unwrap();
await logIn(fingerprint);

navigate('/dashboard/wallets/1');
} catch (error) {
Expand Down
9 changes: 4 additions & 5 deletions packages/wallets/src/components/WalletImport.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { english } from '@chia-network/api';
import { useAddPrivateKeyMutation, useLogInMutation } from '@chia-network/api-react';
import { useAddPrivateKeyMutation } from '@chia-network/api-react';
import {
AlertDialog,
Autocomplete,
Expand All @@ -11,6 +11,7 @@ import {
useOpenDialog,
useTrans,
TextField,
useAuth,
} from '@chia-network/core';
import { Trans } from '@lingui/macro';
import { Typography, Container, Grid } from '@mui/material';
Expand Down Expand Up @@ -39,7 +40,7 @@ type FormData = {
export default function WalletImport() {
const navigate = useNavigate();
const [addPrivateKey] = useAddPrivateKeyMutation();
const [logIn] = useLogInMutation();
const { logIn } = useAuth();
const trans = useTrans();
const openDialog = useOpenDialog();
const [mnemonicPasteOpen, setMnemonicPasteOpen] = React.useState(false);
Expand Down Expand Up @@ -125,9 +126,7 @@ export default function WalletImport() {
...(label && { label: label.trim() }), // omit `label` if label is undefined/empty. backend returns an error if label is set and undefined/empty
}).unwrap();

await logIn({
fingerprint,
}).unwrap();
await logIn(fingerprint);

navigate('/dashboard/wallets/1');
}
Expand Down

0 comments on commit 60bfd2d

Please sign in to comment.