This repository has been archived by the owner on Nov 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Use QuillContext in Confirm dialog #264
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { FunctionComponent, useEffect, useState } from 'react'; | ||
import { runtime, storage } from 'webextension-polyfill'; | ||
import { FunctionComponent, useState } from 'react'; | ||
import { runtime } from 'webextension-polyfill'; | ||
|
||
// components, styles and UI | ||
import { Check, X, CaretLeft, CaretRight } from 'phosphor-react'; | ||
|
@@ -12,37 +12,37 @@ import { | |
} from '../types/Rpc'; | ||
import TransactionCard from './TransactionCard'; | ||
import onAction from '../helpers/onAction'; | ||
import { useQuill } from '../QuillContext'; | ||
import useCell from '../cells/useCell'; | ||
import Loading from '../components/Loading'; | ||
|
||
const Confirm: FunctionComponent = () => { | ||
const [id, setId] = useState<string | null>(); | ||
const [actions, setActions] = useState<SendTransactionParams[]>([]); | ||
const quill = useQuill(); | ||
|
||
const id = new URL(window.location.href).searchParams.get('id'); | ||
const transactions = useCell(quill.cells.transactions); | ||
|
||
const [current, setCurrent] = useState<number>(0); | ||
|
||
useEffect(() => { | ||
const params = new URL(window.location.href).searchParams; | ||
const txid = params.get('id'); | ||
setId(txid); | ||
if (transactions === undefined) { | ||
return <Loading />; | ||
} | ||
|
||
const fetchTx = async () => { | ||
const data = await storage.local.get('transactions'); | ||
const tx = data.transactions.value.outgoing.find( | ||
(t: any) => t.id === txid, | ||
); | ||
setActions(tx.actions); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If tx was not found this would have thrown an error. This is now handled more gracefully as |
||
}; | ||
const tx = transactions.outgoing.find((t) => t.id === id); | ||
|
||
fetchTx(); | ||
}, []); | ||
if (tx === undefined) { | ||
return <>Error: Tx not found</>; | ||
} | ||
|
||
const respondTx = (result: PromptMessage['result']) => { | ||
runtime.sendMessage(undefined, { id, result }); | ||
}; | ||
|
||
const nextTx = () => { | ||
setCurrent((current + 1) % actions.length); | ||
setCurrent((current + 1) % tx.actions.length); | ||
}; | ||
const prevTx = () => { | ||
setCurrent((current - 1) % actions.length); | ||
setCurrent((current - 1) % tx.actions.length); | ||
}; | ||
|
||
const calculateTotal = (allActions: SendTransactionParams[]) => { | ||
|
@@ -72,9 +72,9 @@ const Confirm: FunctionComponent = () => { | |
|
||
<div className="mt-4">AppName is making requests to your wallet</div> | ||
|
||
{actions.length > 1 && ( | ||
{tx.actions.length > 1 && ( | ||
<div className="mt-4 flex justify-end text-body self-center gap-3"> | ||
{current + 1} of {actions?.length} | ||
{current + 1} of {tx.actions?.length} | ||
<div | ||
className="bg-grey-400 rounded-md p-1 hover:bg-grey-500 cursor-pointer" | ||
{...onAction(prevTx)} | ||
|
@@ -92,14 +92,16 @@ const Confirm: FunctionComponent = () => { | |
|
||
<div className="flex flex-col"> | ||
<div className="mt-4"> | ||
{actions[current] && <TransactionCard {...actions[current]} />} | ||
{tx.actions[current] && ( | ||
<TransactionCard {...tx.actions[current]} /> | ||
)} | ||
</div> | ||
|
||
<div className="mt-4 p-4 bg-grey-300 rounded-md flex justify-between h-20"> | ||
<div className="">Total Transaction Fees</div> | ||
<div className="text-right"> | ||
<div className="font-bold">USD $0.0</div> | ||
<div className="">{calculateTotal(actions)} ETH</div> | ||
<div className="">{calculateTotal(tx.actions)} ETH</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
import '../styles/index.scss'; | ||
import './styles.scss'; | ||
|
||
import ReactDOM from 'react-dom'; | ||
import Browser from 'webextension-polyfill'; | ||
|
||
import QuillEthereumProvider from '../QuillEthereumProvider'; | ||
import Confirm from './Confirm'; | ||
import '../styles/index.scss'; | ||
import './styles.scss'; | ||
import { QuillContextProvider } from '../QuillContext'; | ||
|
||
window.ethereum = new QuillEthereumProvider(true); | ||
|
||
window.debug ??= {}; | ||
window.debug.Browser = Browser; | ||
|
||
ReactDOM.render(<Confirm />, document.getElementById('confirm-root')); | ||
ReactDOM.render( | ||
<QuillContextProvider> | ||
<Confirm /> | ||
</QuillContextProvider>, | ||
document.getElementById('confirm-root'), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 10 additions & 10 deletions
20
extension/source/Home/QuillContext.tsx → extension/source/QuillContext.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use of
any
here is what really prompted this. Trying to clean up all our linting issues.