Skip to content

Commit 41d8bf2

Browse files
committed
Merge branch 'master' into fiat
2 parents e5a701e + 1bf2900 commit 41d8bf2

File tree

5 files changed

+103
-57
lines changed

5 files changed

+103
-57
lines changed

code/client/src/components/Layout.jsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,30 @@ const CardStyle = {
1717
WebkitBackdropFilter: 'blur(10px)'
1818
}
1919

20+
export const SpaceCapped = ({ isMobile, children }) => {
21+
return (
22+
<Space
23+
direction='vertical'
24+
size='large'
25+
style={{
26+
height: '100%',
27+
width: '100%',
28+
maxWidth: 400,
29+
justifyContent: 'start',
30+
paddingTop: isMobile ? 32 : 192,
31+
display: 'flex'
32+
}}
33+
>
34+
{children}
35+
</Space>
36+
)
37+
}
38+
2039
export const FloatContainer = ({ isMobile, children }) => {
2140
return (
2241
<Card style={CardStyle} bodyStyle={{ height: '100%' }}>
2342
<Row justify='center'>
24-
<Space
25-
direction='vertical'
26-
size='large'
27-
style={{
28-
height: '100%',
29-
width: '100%',
30-
maxWidth: 400,
31-
justifyContent: 'start',
32-
paddingTop: isMobile ? 32 : 192,
33-
display: 'flex'
34-
}}
35-
>
36-
{children}
37-
</Space>
43+
<SpaceCapped isMobile={isMobile}>{children}</SpaceCapped>
3844
</Row>
3945
</Card>
4046
)

code/client/src/pages/Show/SetRecovery.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const SetRecovery = ({ address, onClose, show }) => {
3030
const { otpInput, otp2Input } = otpState
3131
const resetOtp = otpState.resetOtp
3232

33-
const helpers = ShowUtils.buildHelpers({
33+
const { prepareValidation, ...helpers } = ShowUtils.buildHelpers({
3434
setStage,
3535
resetOtp,
3636
network,

code/client/src/pages/Show/Upgrade.jsx

Lines changed: 69 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import ONEUtil from '../../../../lib/util'
55
import util, { useWindowDimensions } from '../../util'
66
import config from '../../config'
77
import BN from 'bn.js'
8-
import { Button, Card, Typography, Space, Row, Steps } from 'antd'
8+
import { Button, Card, Typography, Space, Row, Steps, Timeline } from 'antd'
99
import message from '../../message'
1010
import { OtpStack, useOtpState } from '../../components/OtpStack'
1111
import { useRandomWorker } from './randomWorker'
@@ -16,6 +16,7 @@ import { api } from '../../../../lib/api'
1616
import { walletActions } from '../../state/modules/wallet'
1717
import { useHistory } from 'react-router'
1818
import Paths from '../../constants/paths'
19+
import WalletAddress from '../../components/WalletAddress'
1920
const { Title, Text, Link } = Typography
2021
const { Step } = Steps
2122
const CardStyle = {
@@ -43,15 +44,13 @@ const Upgrade = ({ address, onClose }) => {
4344
const canUpgrade = majorVersion >= config.minUpgradableVersion
4445
const latestVersion = { majorVersion: ONEConstants.MajorVersion, minorVersion: ONEConstants.MinorVersion }
4546
const maxSpend = util.getMaxSpending(wallet)
46-
const { formatted: maxSpendFormatted } = util.computeBalance(maxSpend)
47+
const { formatted: maxSpendFormatted } = util.computeBalance(maxSpend.toString())
4748
const balances = useSelector(state => state.wallet.balances)
48-
const { balance, formatted } = util.computeBalance(balances[address])
49-
const oneLastResort = util.safeOneAddress(lastResortAddress)
50-
const oneAddress = util.safeOneAddress(address)
49+
const { balance } = util.computeBalance(balances[address])
5150
const balanceGreaterThanLimit = new BN(balance).gt(new BN(maxSpend))
52-
53-
const excessBalance = balanceGreaterThanLimit ? new BN(balance).sub(new BN(maxSpend)) : new BN(0)
54-
const { formatted: excessBalanceFormatted } = util.computeBalance(excessBalance.toString())
51+
const needSetRecoveryAddressFirst = balanceGreaterThanLimit && util.isDefaultRecoveryAddress(lastResortAddress)
52+
const needSpecialSteps = balanceGreaterThanLimit && !util.isDefaultRecoveryAddress(lastResortAddress)
53+
const [minTransferGas] = useState(100000)
5554
const { isMobile } = useWindowDimensions()
5655

5756
const { state: otpState } = useOtpState()
@@ -60,7 +59,7 @@ const Upgrade = ({ address, onClose }) => {
6059
const [stage, setStage] = useState(-1)
6160
const { resetWorker, recoverRandomness } = useRandomWorker()
6261

63-
const { onCommitError, onCommitFailure, onRevealFailure, onRevealError, onRevealAttemptFailed, onRevealSuccess, prepareValidation, prepareProofFailed } = ShowUtils.buildHelpers({ setStage, resetOtp, network, resetWorker })
62+
const { prepareValidation, onRevealSuccess, ...helpers } = ShowUtils.buildHelpers({ setStage, resetOtp, network, resetWorker })
6463

6564
const doUpgrade = async () => {
6665
if (stage >= 0) {
@@ -79,7 +78,10 @@ const Upgrade = ({ address, onClose }) => {
7978
spendingInterval
8079
} = await api.blockchain.getWallet({ address, raw: true })
8180
const backlinks = await api.blockchain.getBacklinks({ address })
82-
const oldCores = await api.blockchain.getOldInfos({ address, raw: true })
81+
let oldCores = []
82+
if (majorVersion >= 14) {
83+
oldCores = await api.blockchain.getOldInfos({ address, raw: true })
84+
}
8385
const transformedLastResortAddress = util.isDefaultRecoveryAddress(lastResortAddress) ? ONEConstants.TreasuryAddress : lastResortAddress
8486
const { address: newAddress } = await api.relayer.create({
8587
root,
@@ -101,18 +103,13 @@ const Upgrade = ({ address, onClose }) => {
101103
otp,
102104
otp2,
103105
recoverRandomness,
104-
prepareProofFailed,
105106
commitHashGenerator: ONE.computeForwardHash,
106107
commitHashArgs: { address: newAddress },
107108
beforeCommit: () => setStage(1),
108109
afterCommit: () => setStage(2),
109-
onCommitError,
110-
onCommitFailure,
111110
revealAPI: api.relayer.revealForward,
112111
revealArgs: { dest: newAddress },
113-
onRevealFailure,
114-
onRevealError,
115-
onRevealAttemptFailed,
112+
...helpers,
116113
onRevealSuccess: async (txId) => {
117114
onRevealSuccess(txId)
118115
setStage(-1)
@@ -143,6 +140,10 @@ const Upgrade = ({ address, onClose }) => {
143140
setSkipUpdate(true)
144141
onClose && onClose()
145142
}
143+
const skipVersion = () => {
144+
dispatch(walletActions.userSkipVersion({ address, version: ONEUtil.getVersion(latestVersion) }))
145+
skip()
146+
}
146147
if (!requireUpdate || skipUpdate || !canUpgrade || temp || !util.isEmptyAddress(forwardAddress)) {
147148
return <></>
148149
}
@@ -157,6 +158,8 @@ const Upgrade = ({ address, onClose }) => {
157158
height: '100%',
158159
justifyContent: 'start',
159160
paddingTop: isMobile ? 32 : 192,
161+
paddingLeft: isMobile ? 16 : 64,
162+
paddingRight: isMobile ? 16 : 64,
160163
display: 'flex'
161164
}}
162165
>
@@ -166,37 +169,61 @@ const Upgrade = ({ address, onClose }) => {
166169
<Text>Your wallet: v{ONEUtil.getVersion(wallet)}</Text>
167170
<Text>Latest version: v{ONEUtil.getVersion(latestVersion)}</Text>
168171
<Button type='primary' shape='round' size='large' onClick={() => setConfirmUpgradeVisible(true)}>Upgrade Now</Button>
169-
<Button type='text' danger onClick={skip}>Do it later</Button>
172+
<Button size='large' shape='round' onClick={skip}>Do it later</Button>
173+
<Button type='text' danger onClick={skipVersion}>Skip this version</Button>
170174
<Text>For more details about this upgrade, see <Link target='_blank' href={util.releaseNotesUrl(latestVersion)} rel='noreferrer'> release notes for v{ONEUtil.getVersion(latestVersion)}</Link></Text>
171175
</>}
172176
{confirmUpgradeVisible &&
173177
<>
174-
<OtpStack shouldAutoFocus walletName={wallet.name} doubleOtp={doubleOtp} otpState={otpState} onComplete={doUpgrade} action='confirm upgrade' />
178+
{needSetRecoveryAddressFirst &&
179+
<>
180+
<Title level={4}>
181+
You have a high value wallet.
182+
</Title>
183+
<Title level={4}>
184+
Please set a recovery address first.
185+
</Title>
186+
<Button size='large' type='primary' shape='round' onClick={() => { skip(); history.push(Paths.showAddress(address, 'help')) }}>Set Now</Button>
187+
</>}
188+
{needSpecialSteps &&
189+
<>
190+
<Title type='danger' level={4}>
191+
You have a high value wallet. Follow these steps:
192+
</Title>
193+
<Steps current={0} direction='vertical'>
194+
<Step title='Confirm the upgrade' description={`You will get a new address. Only ${maxSpendFormatted} ONE will there. Don't panic.`} />
195+
<Step
196+
title='Approve asset transfer'
197+
description={(
198+
<Space direction='vertical'>
199+
<Text>Send 0.1 ONE from your recovery address</Text>
200+
<WalletAddress address={lastResortAddress} showLabel alwaysShowOptions />
201+
<Text>to the current address <b>(use at least {minTransferGas} gas limit)</b></Text>
202+
<WalletAddress address={address} showLabel alwaysShowOptions />
203+
<Text>(To abort upgrade, recover assets, and deprecate the wallet, send 1.0 ONE instead)</Text>
204+
</Space>)}
205+
/>
206+
</Steps>
207+
208+
</>}
209+
{!needSetRecoveryAddressFirst &&
210+
<>
211+
<OtpStack shouldAutoFocus walletName={wallet.name} doubleOtp={doubleOtp} otpState={otpState} onComplete={doUpgrade} action='confirm upgrade' />
212+
213+
<Title level={3}>
214+
How upgrade works:
215+
</Title>
216+
<Timeline>
217+
<Timeline.Item>Each upgrade gives you a new address</Timeline.Item>
218+
<Timeline.Item>Your old address auto-forward assets to new address</Timeline.Item>
219+
<Timeline.Item>In rare cases, some assets may be left over (e.g. ERC20 tokens)</Timeline.Item>
220+
<Timeline.Item>You can take control of old addresses (under "About" tab)</Timeline.Item>
221+
<Timeline.Item>You can inspect and reclaim what's left there at any time</Timeline.Item>
222+
</Timeline>
223+
</>}
224+
{stage < 0 && <Button size='large' shape='round' onClick={skip}>Do it later</Button>}
225+
{stage < 0 && <Button type='text' danger onClick={skipVersion}>Skip this version</Button>}
175226

176-
<Text type='secondary'>
177-
How it works:
178-
<ul>
179-
<li>Your will get a new wallet address. Everything else remains the same (e.g. authenticator)</li>
180-
<li>From now on, everything sent to your old address will be forwarded to the new address</li>
181-
<li>All your collectibles will be immediately transferred to your new address</li>
182-
<li>All tokens you sent (not swapped) at least once will be transferred to the new address </li>
183-
<li>Your new address can fully control your old address, and claim anything not transferred</li>
184-
{!balanceGreaterThanLimit && <li> All your funds ({formatted} ONE) will be immediately transferred to your new address</li>}
185-
<li>If there is anything not automatically transferred, you will be able to reclaim them after upgrade</li>
186-
</ul>
187-
</Text>
188-
{balanceGreaterThanLimit &&
189-
<Text type='danger'>
190-
You have a high value wallet. There are some extra steps for you:
191-
<ul>
192-
<li> {maxSpendFormatted} ONE will be immediately transferred to your new address</li>
193-
<li> You need to approve transferring the rest ({excessBalanceFormatted} ONE) by sending some ONE to the old address</li>
194-
<li> Your recovery address is {oneLastResort}</li>
195-
<li> Send any amount (except 1.0 ONE) to {oneAddress}</li>
196-
<li> If you change your mind, you can still send 1.0 ONE from your recovery address to stop the upgrade and reclaim all funds</li>
197-
</ul>
198-
</Text>}
199-
{stage < 0 && <Button type='text' danger onClick={skip}>Do it later</Button>}
200227
</>}
201228
{stage >= 0 && (
202229
<Row>

code/client/src/state/modules/wallet/actions.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const bindDomain = createAction('BIND_DOMAIN')
3737
// User has acknowledged that they has been notified to save the wallet address for a created wallet.
3838
const userAcknowledgedToSaveAddress = createAction('USER_ACKNOWLEDGED_TO_SAVE_ADDRESS')
3939
const userAcknowledgedNewRoot = createAction('USER_ACKNOWLEDGED_NEW_ROOT')
40+
const userSkipVersion = createAction('USER_SKIP_VERSION')
4041

4142
const setDev = createAction('SET_DEV')
4243

@@ -65,6 +66,7 @@ export default {
6566

6667
userAcknowledgedToSaveAddress,
6768
userAcknowledgedNewRoot,
69+
userSkipVersion,
6870

6971
trackTokens,
7072
untrackTokens,

code/client/src/state/modules/wallet/reducers.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,17 @@ const reducer = handleActions(
213213
}
214214
}),
215215

216+
[walletActions.userSkipVersion]: (state, action) => ({
217+
...state,
218+
wallets: {
219+
...state.wallets,
220+
[action.payload.address]: {
221+
...state.wallets[action.payload.address],
222+
skipVersion: action.payload.version
223+
}
224+
}
225+
}),
226+
216227
[walletActions.setDev]: (state, action) => ({
217228
...state,
218229
dev: action.payload

0 commit comments

Comments
 (0)