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

Tim/ledger UI fixes #496

Merged
merged 3 commits into from
Jul 3, 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
10 changes: 8 additions & 2 deletions src/app/components/sendForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,17 @@ function SendForm({
stxMemo,
}: Props) {
const { t } = useTranslation('translation', { keyPrefix: 'SEND' });
// TODO tim: use context instead of duplicated local state and parent state (as props)
const [amount, setAmount] = useState(amountToSend ?? '');
const [recipientAddress, setRecipientAddress] = useState(recipient ?? '');
const [memo, setMemo] = useState(stxMemo ?? '');
const [fiatAmount, setFiatAmount] = useState<string | undefined>('0');
const [switchToFiat, setSwitchToFiat] = useState(false);
const [addressError, setAddressError] = useState<string | undefined>(recepientError);
const [recipientAddress, setRecipientAddress] = useState(recipient ?? '');
const navigate = useNavigate();

const {
stxBtcRate, btcFiatRate, fiatCurrency, stxAddress,
stxBtcRate, btcFiatRate, fiatCurrency, stxAddress, selectedAccount
} = useSelector(
(state: StoreState) => state.walletState,
);
Expand All @@ -243,6 +244,11 @@ function SendForm({
currencyType,
);

useEffect(() => {
setAmount('');
setRecipientAddress('');
}, [selectedAccount]);

useEffect(() => {
if (recepientError) {
if (associatedAddress !== '' && recepientError.includes(t('ERRORS.ADDRESS_INVALID'))) {
Expand Down
3 changes: 2 additions & 1 deletion src/app/screens/accountList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import styled from 'styled-components';
import Plus from '@assets/img/dashboard/plus.svg';
import ConnectLedger from '@assets/img/dashboard/connect_ledger.svg';
import { useDispatch } from 'react-redux';
import { selectAccount } from '@stores/wallet/actions/actionCreators';
import { selectAccount, setShouldResetUserFlow } from '@stores/wallet/actions/actionCreators';
import Seperator from '@components/seperator';
import { Account } from '@secretkeylabs/xverse-core/types';
import useWalletSelector from '@hooks/useWalletSelector';
Expand Down Expand Up @@ -90,6 +90,7 @@ function AccountList(): JSX.Element {
account.accountName
)
);
dispatch(setShouldResetUserFlow(true));
navigate('/');
};

Expand Down
19 changes: 16 additions & 3 deletions src/app/screens/confirmBtcTransaction/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import useBtcClient from '@hooks/useBtcClient';
import { isLedgerAccount } from '@utils/helper';
import BigNumber from 'bignumber.js';
import { LedgerTransactionType } from '@screens/ledger/confirmLedgerTransaction';
import { useDispatch } from 'react-redux';
import { setShouldResetUserFlow } from '@stores/wallet/actions/actionCreators';

const BottomBarContainer = styled.h1((props) => ({
marginTop: props.theme.spacing(5),
Expand All @@ -25,9 +27,7 @@ const BottomBarContainer = styled.h1((props) => ({
function ConfirmBtcTransaction() {
const navigate = useNavigate();
const { t } = useTranslation('translation', { keyPrefix: 'CONFIRM_TRANSACTION' });
const {
network, ordinalsAddress, btcAddress, selectedAccount,
} = useWalletSelector();
const { ordinalsAddress, btcAddress, selectedAccount, shouldResetUserFlow } = useWalletSelector();
const btcClient = useBtcClient();
const [recipientAddress, setRecipientAddress] = useState('');
const [signedTx, setSignedTx] = useState<string>('');
Expand All @@ -41,6 +41,7 @@ function ConfirmBtcTransaction() {
fee, amount, signedTxHex, recipient, isRestoreFundFlow, unspentUtxos, isBrc20TokenFlow,
feePerVByte,
} = location.state;
const dispatch = useDispatch();

const {
isLoading,
Expand All @@ -61,6 +62,18 @@ function ConfirmBtcTransaction() {
});
};

useEffect(() => {
if (shouldResetUserFlow) {
navigate('/send-btc', {
state: {
amount,
recipientAddress,
},
});
dispatch(setShouldResetUserFlow(false));
}
}, [shouldResetUserFlow]);

const onContinueButtonClick = () => {
mutate({ signedTx });
};
Expand Down
13 changes: 12 additions & 1 deletion src/app/screens/sendBtc/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import BigNumber from 'bignumber.js';
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useMutation } from '@tanstack/react-query';
import { useSelector } from 'react-redux';
import { useDispatch, useSelector } from 'react-redux';
import { useLocation, useNavigate } from 'react-router-dom';
import SendForm from '@components/sendForm';
import TopRow from '@components/topRow';
Expand All @@ -15,6 +15,7 @@ import { BITCOIN_DUST_AMOUNT_SATS } from '@utils/constants';
import { Recipient, SignedBtcTx } from '@secretkeylabs/xverse-core/transactions/btc';
import { ErrorCodes, ResponseError } from '@secretkeylabs/xverse-core';
import { isInOptions } from '@utils/helper';
import { setShouldResetUserFlow } from '@stores/wallet/actions/actionCreators';

function SendBtcScreen() {
const location = useLocation();
Expand All @@ -36,8 +37,10 @@ function SendBtcScreen() {
selectedAccount,
seedPhrase,
btcFiatRate,
shouldResetUserFlow,
} = useSelector((state: StoreState) => state.walletState);
const { t } = useTranslation('translation', { keyPrefix: 'SEND' });
const dispatch = useDispatch();

const navigate = useNavigate();
const {
Expand Down Expand Up @@ -79,6 +82,14 @@ function SendBtcScreen() {
}
}, [data]);

useEffect(() => {
if (shouldResetUserFlow) {
setAmount('');
setRecipientAddress('');
dispatch(setShouldResetUserFlow(false));
}
}, [shouldResetUserFlow]);

useEffect(() => {
if (recipientAddress && amount && txError) {
if (Number(txError) === ErrorCodes.InSufficientBalance) {
Expand Down
2 changes: 2 additions & 0 deletions src/app/stores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const storeMiddleware = [
actions.StoreEncryptedSeedKey,
actions.SetWalletSeedPhraseKey,
actions.UnlockWalletKey,
actions.SelectAccountKey,
actions.SetShouldResetUserFlowKey
],
}),
];
Expand Down
9 changes: 9 additions & 0 deletions src/app/stores/wallet/actions/actionCreators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,12 @@ export function setWalletLockPeriodAction(
walletLockPeriod,
};
}

export function setShouldResetUserFlow(
shouldResetUserFlow: boolean
): actions.SetShouldResetUserFlow {
return {
type: actions.SetShouldResetUserFlowKey,
shouldResetUserFlow
};
}
7 changes: 7 additions & 0 deletions src/app/stores/wallet/actions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const AddLedgerAccountKey = 'AddLedgerAccountKey';
export const SetBrcCoinsListKey = 'SetBrcCoinsList';

export const SetWalletLockPeriodKey = 'SetWalletLockPeriod';
export const SetShouldResetUserFlowKey = 'SetShouldResetUserFlow';

export enum WalletSessionPeriods {
LOW = 1,
Expand Down Expand Up @@ -85,6 +86,7 @@ export interface WalletState {
accountName: string | undefined;
btcApiUrl: string;
walletLockPeriod: WalletSessionPeriods;
shouldResetUserFlow: boolean;
}

export interface SetWallet {
Expand Down Expand Up @@ -245,3 +247,8 @@ export type WalletActions =
| SetBrcCoinsData
| SetWalletLockPeriod
| DisableWalletExistsGuard;

export type ShouldResetUserFlow = {
type: typeof ShouldResetUserFlowKey;
shouldResetUserFlow: boolean;
}
7 changes: 7 additions & 0 deletions src/app/stores/wallet/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
WalletActions,
WalletSessionPeriods,
WalletState,
SetShouldResetUserFlowKey,
} from './actions/types';

const initialWalletState: WalletState = {
Expand Down Expand Up @@ -64,6 +65,7 @@ const initialWalletState: WalletState = {
accountType: 'software',
accountName: undefined,
walletLockPeriod: WalletSessionPeriods.STANDARD,
shouldResetUserFlow: false,
};

const walletReducer = (
Expand Down Expand Up @@ -209,6 +211,11 @@ const walletReducer = (
...state,
walletLockPeriod: action.walletLockPeriod,
};
case SetShouldResetUserFlowKey:
return {
...state,
shouldResetUserFlow: action.shouldResetUserFlow
}
default:
return state;
}
Expand Down