-
Notifications
You must be signed in to change notification settings - Fork 89
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
feat(wallets): trezor wallet support #3020
Merged
Merged
Changes from 15 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
0c835d5
chore: trezor setup
shoom3301 7786555
feat(trezor): sign and send transaction
shoom3301 e1d590c
feat(trezor): display approve tx error in modal
shoom3301 36072a3
fix(trezor): use gas price for tx
shoom3301 33e844d
feat(trezor): sign typed data
shoom3301 9d660bd
fix(trezor): display icon in pending tx modal
shoom3301 d231b4b
chore: fix trezor icon
shoom3301 a676447
fix(trezor): allow switching network
shoom3301 abe31ad
feat(trezor): selector for account index
shoom3301 8d0dc00
refactor(trezor): extract sendTransactionHandler
shoom3301 2cbd907
refactor(trezor): extract TrezorConnector
shoom3301 9b1148e
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 febf67a
chore: fix double activation
shoom3301 ad89d37
fix: fix metamask approving banner conditions
shoom3301 7611f1a
chore: fix gasPrice
shoom3301 2cdad5b
feat(wallets): display connection error in modal
shoom3301 d38f2dd
fix: dispose trezor on connection fail
shoom3301 15a331e
fix: deactivate connector on trezor disconnect
shoom3301 227271b
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 d38b3bf
chore: merge develop
shoom3301 3f01fe3
chore: fix
shoom3301 0e7dcab
chore: temp fix
shoom3301 006226c
chore: temp fix
shoom3301 dddc42a
refactor: address code review issues
shoom3301 60d997c
chore: revert fix
shoom3301 d3d866e
fix: clean state on deactivate
shoom3301 b561239
chore: refactor
shoom3301 3a3ceb6
feat(trezor): load first 100 accounts
shoom3301 35610f1
feat(trezor): select account index in one click
shoom3301 4e64011
feat(trezor): hide the wallet under feature-flag
shoom3301 4fbe323
chore: hide Trezor by feature-flag
shoom3301 8906b31
feat(trezor): display accounts balances
shoom3301 98a6b65
Merge branch 'develop' of https://github.com/cowprotocol/cowswap into…
shoom3301 ff3ff07
chore: cosmos AccountIndexSelect
shoom3301 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
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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import React, { useCallback } from 'react' | ||
import React, { useCallback, useState } from 'react' | ||
|
||
import { Currency, CurrencyAmount } from '@uniswap/sdk-core' | ||
|
||
import { useShouldZeroApprove } from 'common/hooks/useShouldZeroApprove' | ||
import { useZeroApprove } from 'common/hooks/useZeroApprove' | ||
import { ApproveButton } from 'common/pure/ApproveButton' | ||
import { CowModal } from 'common/pure/Modal' | ||
import { TransactionErrorContent } from 'common/pure/TransactionErrorContent' | ||
|
||
import { useTradeApproveCallback } from './useTradeApproveCallback' | ||
import { useTradeApproveState } from './useTradeApproveState' | ||
|
@@ -24,16 +26,26 @@ export function TradeApproveButton(props: TradeApproveButtonProps) { | |
const tradeApproveCallback = useTradeApproveCallback(amountToApprove) | ||
const shouldZeroApprove = useShouldZeroApprove(amountToApprove) | ||
const zeroApprove = useZeroApprove(amountToApprove.currency) | ||
const [error, setError] = useState<string | null>(null) | ||
const onDismissError = () => setError(null) | ||
|
||
const handleApprove = useCallback(async () => { | ||
if (shouldZeroApprove) { | ||
await zeroApprove() | ||
try { | ||
if (shouldZeroApprove) { | ||
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. Before we didn't display errors from token approving |
||
await zeroApprove() | ||
} | ||
await tradeApproveCallback() | ||
} catch (error) { | ||
setError(typeof error === 'string' ? error : error.message || error.toString()) | ||
} | ||
await tradeApproveCallback() | ||
}, [tradeApproveCallback, zeroApprove, shouldZeroApprove]) | ||
}, [tradeApproveCallback, zeroApprove, shouldZeroApprove, setError]) | ||
|
||
return ( | ||
<> | ||
<CowModal isOpen={!!error} onDismiss={onDismissError}> | ||
{error && <TransactionErrorContent message={error} onDismiss={onDismissError} />} | ||
</CowModal> | ||
|
||
<ApproveButton isDisabled={isDisabled} currency={currency} onClick={handleApprove} state={approvalState} /> | ||
|
||
{children} | ||
|
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
34 changes: 34 additions & 0 deletions
34
src/modules/account/containers/AccountDetails/HwAccountIndexSelector.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useAtom } from 'jotai/index' | ||
import { FormEvent, useCallback, useRef } from 'react' | ||
|
||
import styled from 'styled-components/macro' | ||
|
||
import { hwAccountIndexAtom } from 'modules/wallet/api/state' | ||
|
||
const Wrapper = styled.form` | ||
font-size: 14px; | ||
margin: 10px 0; | ||
` | ||
|
||
// TODO: add styles | ||
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. |
||
export function HwAccountIndexSelector() { | ||
const accountIndexRef = useRef<HTMLInputElement>(null) | ||
const [hwAccountIndex, setHwAccountIndex] = useAtom(hwAccountIndexAtom) | ||
|
||
const onHwAccountIndexChange = useCallback( | ||
(event: FormEvent) => { | ||
event.preventDefault() | ||
|
||
setHwAccountIndex(+(accountIndexRef.current?.value || 0)) | ||
}, | ||
[setHwAccountIndex] | ||
) | ||
|
||
return ( | ||
<Wrapper onSubmit={(event) => onHwAccountIndexChange(event)}> | ||
<p>Hardware account index:</p> | ||
<input ref={accountIndexRef} placeholder={hwAccountIndex.toString()} type="number" step={1} /> | ||
<button>Update</button> | ||
</Wrapper> | ||
) | ||
} |
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 @@ | ||
export * from './state/gasPriceAtom' |
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,10 @@ | ||
import { atom } from 'jotai' | ||
|
||
interface GasPriceState { | ||
lastUpdate: string | ||
average: string | null | ||
fast: string | null | ||
slow: string | null | ||
} | ||
|
||
export const gasPriceAtom = atom<GasPriceState | null>(null) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.
Oops, something went wrong.
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.
@trezor/connect-plugin-ethereum
requires@metamask/eth-sig-util
that requireszlib
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.
Regarding
@metamask/eth-sig-util
Does it need to be explicitly installed? Isn't it enough to have it installed by the
@trezor
package?