Skip to content

Commit bc4f971

Browse files
committed
add spinner to tx modal and other fixes
1 parent db46c56 commit bc4f971

File tree

5 files changed

+52
-36
lines changed

5 files changed

+52
-36
lines changed

src/components/Modal.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import { ArrowNarrowLeftIcon, PlusIcon } from '@heroicons/react/solid';
22
import { ReactNode, useEffect, useRef } from 'react';
33
import ReactDOM from 'react-dom';
44
import { useKeyPress } from '../utils/hooks';
5+
import Spinner from './Spinner';
56

67
type Props = {
78
fullscreen?: boolean;
9+
spinner?: boolean;
810
bottom?: boolean;
911
noHeader?: boolean;
1012
heading?: string;
@@ -31,6 +33,7 @@ const Modal = ({
3133
plusIcon,
3234
buttonText,
3335
onButtonClick,
36+
spinner,
3437
bottom,
3538
noBackArrow,
3639
}: Props) => {
@@ -62,7 +65,11 @@ const Modal = ({
6265
mouseDraggingModal.current = false;
6366
}}
6467
>
65-
{fullscreen ? (
68+
{spinner ? (
69+
<div className="w-full h-full xy">
70+
<Spinner />
71+
</div>
72+
) : fullscreen ? (
6673
<div
6774
onClick={(e) => e.stopPropagation()}
6875
className="flex flex-col w-full h-full bg-skin-base"

src/components/TransactionModal.tsx

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import DeterministicIcon from './DeterministicIcon';
2020
import Modal from './Modal';
2121

2222
type Props = State & {
23-
noBackArrow?: boolean;
23+
thirdPartyTx?: boolean;
2424
transaction?: Transaction;
2525
contractFuncParams?: any[];
2626
onBack?: () => void; // clicking back arrow
@@ -55,7 +55,7 @@ const Field = ({
5555
);
5656

5757
const TransactionModal = ({
58-
noBackArrow,
58+
thirdPartyTx,
5959
unsentBlock,
6060
onBack,
6161
onCancel = onBack,
@@ -119,7 +119,7 @@ const TransactionModal = ({
119119
{(!!transaction || !!unsentBlock) && (
120120
<Modal
121121
fullscreen
122-
noBackArrow={noBackArrow || sendingTx}
122+
noBackArrow={thirdPartyTx}
123123
heading={unsentBlock ? i18n.confirmTransaction : i18n.transaction}
124124
onClose={() => onBack && onBack()}
125125
className="flex flex-col"
@@ -225,14 +225,8 @@ const TransactionModal = ({
225225
<Button theme="highlight" label={i18n.close} onClick={onCloseAfterSend!} />
226226
) : (
227227
<>
228+
<Button theme="foreground" label={i18n.cancel} onClick={onCancel!} />
228229
<Button
229-
disabled={!!sendingTx}
230-
theme="foreground"
231-
label={i18n.cancel}
232-
onClick={onCancel!}
233-
/>
234-
<Button
235-
disabled={!!sendingTx}
236230
theme="highlight"
237231
label={i18n.confirm}
238232
onClick={async () => {
@@ -263,32 +257,35 @@ const TransactionModal = ({
263257
);
264258
}
265259

266-
const sanitizedBlock: AccountBlockBlock = {
267-
// Don't want to send `block: res` in case the type of `res` changes and includes `privateKey`
268-
// This ensures the private key is never sent to the content script
269-
blockType: res.blockType,
270-
address: res.address,
271-
fee: res.fee,
272-
data: res.data,
273-
sendBlockHash: res.sendBlockHash,
274-
toAddress: res.toAddress,
275-
tokenId: res.tokenId,
276-
amount: res.amount,
277-
height: res.height,
278-
previousHash: res.previousHash,
279-
difficulty: res.difficulty,
280-
nonce: res.nonce,
281-
signature: res.signature,
282-
publicKey: res.publicKey,
283-
hash: res.hash,
284-
};
285-
triggerInjectedScriptEvent({
286-
type: 'writeAccountBlock',
287-
payload: { block: sanitizedBlock },
288-
});
260+
if (thirdPartyTx) {
261+
const sanitizedBlock: AccountBlockBlock = {
262+
// Don't want to send `block: res` in case the type of `res` changes and includes `privateKey`
263+
// This ensures the private key is never sent to the content script
264+
blockType: res.blockType,
265+
address: res.address,
266+
fee: res.fee,
267+
data: res.data,
268+
sendBlockHash: res.sendBlockHash,
269+
toAddress: res.toAddress,
270+
tokenId: res.tokenId,
271+
amount: res.amount,
272+
height: res.height,
273+
previousHash: res.previousHash,
274+
difficulty: res.difficulty,
275+
nonce: res.nonce,
276+
signature: res.signature,
277+
publicKey: res.publicKey,
278+
hash: res.hash,
279+
};
280+
triggerInjectedScriptEvent({
281+
type: 'writeAccountBlock',
282+
payload: { block: sanitizedBlock },
283+
});
284+
}
289285
} catch (e) {
290286
console.log('error:', e);
291287
toastError(e);
288+
} finally {
292289
sendingTxSet(false);
293290
}
294291
}}
@@ -299,6 +296,11 @@ const TransactionModal = ({
299296
)}
300297
</Modal>
301298
)}
299+
{sendingTx && (
300+
<Modal spinner onClose={() => {}}>
301+
{null}
302+
</Modal>
303+
)}
302304
</>
303305
);
304306
};

src/i18n/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ const en = {
169169
rpcUrlAlreadyInUse: 'RPC URL already in use',
170170
none: 'None',
171171
noPrice: 'No Price',
172+
waitForWalletBalanceToLoad: 'Wait for wallet balance to load',
172173
test: 'test',
173174
'': '',
174175
};

src/pages/Home.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ const Home = ({
5151
viteBalanceInfo,
5252
currencyConversion,
5353
portfolioValue,
54+
toastInfo,
55+
displayedTokenIdsAndNames,
56+
toastError,
5457
}: State) => {
5558
// const quotaBeneficiaryRef = useTextInputRef();
5659
// const lockedAmountRef = useTextInputRef();
@@ -156,9 +159,11 @@ const Home = ({
156159
onClick={async () => {
157160
if (balanceInfoMap) {
158161
sendingSet(true);
159-
const arr = await getTokenApiInfo(Object.keys(balanceInfoMap));
162+
const arr = await getTokenApiInfo(displayedTokenIdsAndNames.map(([tti]) => tti));
160163
tokensInWalletSet(arr);
161164
displayedTokensSet(arr);
165+
} else {
166+
toastInfo(i18n.waitForWalletBalanceToLoad);
162167
}
163168
}}
164169
>
@@ -426,6 +431,7 @@ const Home = ({
426431
tokensInWallet.filter((tokenApiInfo) => {
427432
return (
428433
tokenApiInfo.tokenAddress.includes(search) ||
434+
tokenApiInfo.name.toLocaleLowerCase().includes(search) ||
429435
addIndexToTokenSymbol(tokenApiInfo.symbol, tokenApiInfo.tokenIndex)
430436
.toLocaleLowerCase()
431437
.includes(search)

src/pages/SignTx.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const SignTx = ({ activeAccount, viteBalanceInfo, i18n }: State) => {
5454
<Spinner />
5555
</div>
5656
) : (
57-
<TransactionModal noBackArrow onCancel={() => window.close()} unsentBlock={block} />
57+
<TransactionModal thirdPartyTx onCancel={() => window.close()} unsentBlock={block} />
5858
);
5959
};
6060

0 commit comments

Comments
 (0)