-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from gnosis/transaction-translations
Transaction translations
- Loading branch information
Showing
18 changed files
with
1,142 additions
and
656 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from 'react' | ||
import { RiFileCopy2Line } from 'react-icons/ri' | ||
import { encodeSingle, TransactionInput } from 'react-multisend' | ||
import { toast } from 'react-toastify' | ||
|
||
import { IconButton } from '../../components' | ||
|
||
import classes from './style.module.css' | ||
|
||
interface Props { | ||
transaction: TransactionInput | ||
labeled?: boolean | ||
} | ||
|
||
const CopyToClipboard: React.FC<Props> = ({ transaction, labeled }) => { | ||
const encodedTransaction = encodeSingle(transaction) | ||
|
||
const copyToClipboard = () => { | ||
navigator.clipboard.writeText( | ||
JSON.stringify(encodedTransaction, undefined, 2) | ||
) | ||
toast(<>Transaction data has been copied to clipboard.</>) | ||
} | ||
|
||
if (labeled) { | ||
return ( | ||
<button onClick={copyToClipboard} className={classes.link}> | ||
Copy data | ||
<RiFileCopy2Line /> | ||
</button> | ||
) | ||
} else { | ||
return ( | ||
<IconButton | ||
onClick={copyToClipboard} | ||
title="Copy transaction data to clipboard" | ||
> | ||
<RiFileCopy2Line /> | ||
</IconButton> | ||
) | ||
} | ||
} | ||
|
||
export default CopyToClipboard |
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import React from 'react' | ||
import { RiDeleteBinLine } from 'react-icons/ri' | ||
import { encodeSingle, TransactionInput } from 'react-multisend' | ||
|
||
import { IconButton } from '../../components' | ||
import { ForkProvider } from '../../providers' | ||
import { useConnection } from '../../settings' | ||
import { useProvider } from '../ProvideProvider' | ||
import { useDispatch, useNewTransactions } from '../state' | ||
|
||
import { formatValue } from './formatValue' | ||
import classes from './style.module.css' | ||
|
||
type Props = { | ||
transaction: TransactionInput | ||
index: number | ||
} | ||
|
||
export const Remove: React.FC<Props> = ({ transaction, index }) => { | ||
const provider = useProvider() | ||
const dispatch = useDispatch() | ||
const transactions = useNewTransactions() | ||
const { connection } = useConnection() | ||
|
||
if (!(provider instanceof ForkProvider)) { | ||
// Removing transactions is only supported when using ForkProvider | ||
return null | ||
} | ||
|
||
const handleRemove = async () => { | ||
const laterTransactions = transactions.slice(index + 1) | ||
|
||
// remove the transaction and all later ones from the store | ||
dispatch({ type: 'REMOVE_TRANSACTION', payload: { id: transaction.id } }) | ||
|
||
if (transactions.length === 1) { | ||
// no more recorded transaction remains: we can delete the fork and will create a fresh one once we receive the next transaction | ||
await provider.deleteFork() | ||
return | ||
} | ||
|
||
// revert to checkpoint before the transaction to remove | ||
const checkpoint = transaction.id // the ForkProvider uses checkpoints as IDs for the recorded transactions | ||
await provider.request({ method: 'evm_revert', params: [checkpoint] }) | ||
|
||
// re-simulate all transactions after the removed one | ||
for (let i = 0; i < laterTransactions.length; i++) { | ||
const transaction = laterTransactions[i] | ||
const encoded = encodeSingle(transaction.input) | ||
await provider.request({ | ||
method: 'eth_sendTransaction', | ||
params: [ | ||
{ | ||
to: encoded.to, | ||
data: encoded.data, | ||
value: formatValue(encoded.value), | ||
from: connection.avatarAddress, | ||
}, | ||
], | ||
}) | ||
} | ||
} | ||
|
||
return ( | ||
<IconButton | ||
onClick={handleRemove} | ||
className={classes.removeTransaction} | ||
title="Remove transaction" | ||
> | ||
<RiDeleteBinLine /> | ||
</IconButton> | ||
) | ||
} |
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
Oops, something went wrong.