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

Release v0.26.1 to main #719

Merged
merged 13 commits into from
Dec 19, 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
43 changes: 14 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "xverse-web-extension",
"description": "A Bitcoin wallet for Web3",
"version": "0.26.0",
"version": "0.26.1",
"private": true,
"engines": {
"node": "^18.18.2"
Expand All @@ -10,7 +10,7 @@
"@ledgerhq/hw-transport-webusb": "^6.27.13",
"@phosphor-icons/react": "^2.0.10",
"@react-spring/web": "^9.6.1",
"@secretkeylabs/xverse-core": "5.2.0",
"@secretkeylabs/xverse-core": "5.3.0",
"@stacks/connect": "^6.10.2",
"@stacks/encryption": "4.3.5",
"@stacks/stacks-blockchain-api-types": "6.1.1",
Expand Down
15 changes: 10 additions & 5 deletions src/app/components/guards/auth.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { PropsWithChildren, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import useSeedVault from '@hooks/useSeedVault';
import useWalletSelector from '@hooks/useWalletSelector';
import { useDispatch } from 'react-redux';
import { setWalletUnlockedAction } from '@stores/wallet/actions/actionCreators';
import { PropsWithChildren, useEffect } from 'react';
import { useDispatch } from 'react-redux';
import { useNavigate } from 'react-router-dom';

function AuthGuard({ children }: PropsWithChildren) {
const navigate = useNavigate();
const { masterPubKey, encryptedSeed, isUnlocked } = useWalletSelector();
const { masterPubKey, encryptedSeed, isUnlocked, accountsList } = useWalletSelector();
const { getSeed, hasSeed } = useSeedVault();
const dispatch = useDispatch();

Expand All @@ -26,7 +26,12 @@ function AuthGuard({ children }: PropsWithChildren) {
return;
}
const hasSeedPhrase = await hasSeed();
if (!hasSeedPhrase || !masterPubKey) {
if (
!hasSeedPhrase ||
// We ensure there is at least 1 account with a masterPubKey as the unlock code will select an account if one
// is not selected in the store
(!masterPubKey && (accountsList.length === 0 || !accountsList[0].masterPubKey))
) {
navigate('/landing');
return;
}
Expand Down
24 changes: 22 additions & 2 deletions src/app/components/seedPhraseInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,24 @@ type SeedWordInputProps = {
index: number;
handleChangeInput: (e: React.ChangeEvent<HTMLInputElement>) => void;
handleKeyDownInput: (e: React.KeyboardEvent<HTMLInputElement>) => void;
handlePaste: (pastedText: string) => void;
disabled?: boolean;
};
const SeedWordInput = React.forwardRef<HTMLInputElement, SeedWordInputProps>(
({ value, index, handleChangeInput, handleKeyDownInput, disabled }, ref) => {
const [showValue, setShowValue] = useState(false);
({ value, index, handleChangeInput, handleKeyDownInput, disabled, handlePaste }, ref) => {
const DEV_MODE = process.env.NODE_ENV === 'development';
const [showValue, setShowValue] = useState(DEV_MODE);

const handleFocusInput = () => setShowValue(true);
const handleBlurInput = () => setShowValue(false);
const handlePasteInput = (e: React.ClipboardEvent<HTMLInputElement>) => {
e.preventDefault();

if (DEV_MODE) {
const { clipboardData } = e;
const pastedText = clipboardData.getData('text');
handlePaste(pastedText);
}
};

return (
Expand Down Expand Up @@ -167,6 +175,16 @@ export default function SeedPhraseInput({
});
};

const handlePaste = (pastedText: string) => {
const splitPastedText = pastedText.split(' ');
splitPastedText.forEach((text, index) => {
setSeedInputValues((prevSeed) => {
prevSeed[index] = text;
return [...prevSeed];
});
});
};

useEffect(() => {
const seedPhrase = seedInputValues
.slice(0, !show24Words ? 12 : 24)
Expand All @@ -190,6 +208,7 @@ export default function SeedPhraseInput({
index={index}
handleChangeInput={handleChangeInput(index)}
handleKeyDownInput={handleKeyDownInput(index)}
handlePaste={handlePaste}
ref={(el) => {
inputsRef.current[index] = el;
}}
Expand All @@ -206,6 +225,7 @@ export default function SeedPhraseInput({
index={index}
handleChangeInput={handleChangeInput(index)}
handleKeyDownInput={handleKeyDownInput(index)}
handlePaste={handlePaste}
ref={(el) => {
inputsRef.current[index] = el;
}}
Expand Down
7 changes: 5 additions & 2 deletions src/app/hooks/useDetectOrdinalInSignPsbt.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
Bundle,
getUtxoOrdinalBundle,
getUtxoOrdinalBundleIfFound,
mapRareSatsAPIResponseToBundle,
ParsedPSBT,
} from '@secretkeylabs/xverse-core';
Expand All @@ -21,10 +21,13 @@ const useDetectOrdinalInSignPsbt = () => {

if (parsedPsbt) {
const inputsRequest = parsedPsbt.inputs.map((input) =>
getUtxoOrdinalBundle(network.type, input.txid, input.index),
getUtxoOrdinalBundleIfFound(network.type, input.txid, input.index),
);
const inputsResponse = await Promise.all(inputsRequest);
inputsResponse.forEach((inputResponse, index) => {
if (!inputResponse) {
return;
}
const bundle = mapRareSatsAPIResponseToBundle(inputResponse);
if (
bundle.inscriptions.length > 0 ||
Expand Down
42 changes: 18 additions & 24 deletions src/app/hooks/useWalletReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const useWalletReducer = () => {
currentAccounts,
);

// we sanitise the account to remove any unknown properties which we had in pervious versions of the app
walletAccounts[0] = {
id: walletAccounts[0].id,
btcAddress: walletAccounts[0].btcAddress,
Expand All @@ -77,13 +78,18 @@ const useWalletReducer = () => {
bnsName: walletAccounts[0].bnsName,
};

let selectedAccountData: Account;
let selectedAccountData: Account | undefined;
if (!selectedAccount) {
[selectedAccountData] = walletAccounts;
} else if (isLedgerAccount(selectedAccount)) {
selectedAccountData = ledgerAccountsList[selectedAccount.id];
selectedAccountData = ledgerAccountsList.find((a) => a.id === selectedAccount.id);
} else {
selectedAccountData = walletAccounts[selectedAccount.id];
selectedAccountData = walletAccounts.find((a) => a.id === selectedAccount.id);
}

if (!selectedAccountData) {
// this should not happen but is a good fallback to have, just in case
[selectedAccountData] = walletAccounts;
}

if (!isHardwareAccount(selectedAccountData)) {
Expand Down Expand Up @@ -326,36 +332,24 @@ const useWalletReducer = () => {
};

const addLedgerAccount = async (ledgerAccount: Account) => {
try {
dispatch(updateLedgerAccountsAction([...ledgerAccountsList, ledgerAccount]));
} catch (err) {
return Promise.reject(err);
}
dispatch(updateLedgerAccountsAction([...ledgerAccountsList, ledgerAccount]));
};

const removeLedgerAccount = async (ledgerAccount: Account) => {
try {
dispatch(
updateLedgerAccountsAction(
ledgerAccountsList.filter((account) => account.id !== ledgerAccount.id),
),
);
} catch (err) {
return Promise.reject(err);
}
dispatch(
updateLedgerAccountsAction(
ledgerAccountsList.filter((account) => account.id !== ledgerAccount.id),
),
);
};

const updateLedgerAccounts = async (updatedLedgerAccount: Account) => {
const newLedgerAccountsList = ledgerAccountsList.map((account) =>
account.id === updatedLedgerAccount.id ? updatedLedgerAccount : account,
);
try {
dispatch(updateLedgerAccountsAction(newLedgerAccountsList));
if (isLedgerAccount(selectedAccount) && updatedLedgerAccount.id === selectedAccount?.id) {
switchAccount(updatedLedgerAccount);
}
} catch (err) {
return Promise.reject(err);
dispatch(updateLedgerAccountsAction(newLedgerAccountsList));
if (isLedgerAccount(selectedAccount) && updatedLedgerAccount.id === selectedAccount?.id) {
switchAccount(updatedLedgerAccount);
}
};

Expand Down
12 changes: 9 additions & 3 deletions src/app/screens/confirmFtTransaction/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { deserializeTransaction } from '@stacks/transactions';
import { useMutation } from '@tanstack/react-query';
import { isLedgerAccount } from '@utils/helper';
import BigNumber from 'bignumber.js';
import { useEffect } from 'react';
import { useEffect, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate } from 'react-router-dom';

Expand All @@ -22,8 +22,14 @@ function ConfirmFtTransaction() {
const navigate = useNavigate();
const selectedNetwork = useNetworkSelector();
const location = useLocation();
const { unsignedTx: seedHex, amount, fungibleToken, memo, recepientAddress } = location.state;
const unsignedTx = deserializeTransaction(seedHex);
const {
unsignedTx: unsignedTxHex,
amount,
fungibleToken,
memo,
recepientAddress,
} = location.state;
const unsignedTx = useMemo(() => deserializeTransaction(unsignedTxHex), [unsignedTxHex]);
const { refetch } = useStxWalletData();
const { network, selectedAccount } = useWalletSelector();

Expand Down
4 changes: 2 additions & 2 deletions src/app/screens/confirmNftTransaction/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { deserializeTransaction } from '@stacks/transactions';
import { useMutation } from '@tanstack/react-query';
import { isLedgerAccount } from '@utils/helper';
import BigNumber from 'bignumber.js';
import { useEffect } from 'react';
import { useEffect, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate, useParams } from 'react-router-dom';
import styled from 'styled-components';
Expand Down Expand Up @@ -74,7 +74,7 @@ function ConfirmNftTransaction() {
const nft = nftDetailQuery.data?.data;

const { unsignedTx: unsignedTxHex, recipientAddress } = location.state;
const unsignedTx = deserializeTransaction(unsignedTxHex);
const unsignedTx = useMemo(() => deserializeTransaction(unsignedTxHex), [unsignedTxHex]);
const { network } = useWalletSelector();
const { refetch } = useStxWalletData();
const selectedNetwork = useNetworkSelector();
Expand Down
4 changes: 2 additions & 2 deletions src/app/screens/confirmStxTransaction/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { deserializeTransaction } from '@stacks/transactions';
import { useMutation } from '@tanstack/react-query';
import { isLedgerAccount } from '@utils/helper';
import BigNumber from 'bignumber.js';
import { useEffect, useState } from 'react';
import { useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate } from 'react-router-dom';
import styled from 'styled-components';
Expand All @@ -49,7 +49,7 @@ function ConfirmStxTransaction() {
const location = useLocation();
const selectedNetwork = useNetworkSelector();
const { unsignedTx: stringHex, sponsored, isBrowserTx, tabId, requestToken } = location.state;
const unsignedTx = deserializeTransaction(stringHex);
const unsignedTx = useMemo(() => deserializeTransaction(stringHex), [stringHex]);
useOnOriginTabClose(Number(tabId), () => {
setHasTabClosed(true);
window.scrollTo({ top: 0, behavior: 'smooth' });
Expand Down
Loading
Loading