@@ -5,7 +5,7 @@ import ONEUtil from '../../../../lib/util'
5
5
import util , { useWindowDimensions } from '../../util'
6
6
import config from '../../config'
7
7
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'
9
9
import message from '../../message'
10
10
import { OtpStack , useOtpState } from '../../components/OtpStack'
11
11
import { useRandomWorker } from './randomWorker'
@@ -16,6 +16,7 @@ import { api } from '../../../../lib/api'
16
16
import { walletActions } from '../../state/modules/wallet'
17
17
import { useHistory } from 'react-router'
18
18
import Paths from '../../constants/paths'
19
+ import WalletAddress from '../../components/WalletAddress'
19
20
const { Title, Text, Link } = Typography
20
21
const { Step } = Steps
21
22
const CardStyle = {
@@ -43,15 +44,13 @@ const Upgrade = ({ address, onClose }) => {
43
44
const canUpgrade = majorVersion >= config . minUpgradableVersion
44
45
const latestVersion = { majorVersion : ONEConstants . MajorVersion , minorVersion : ONEConstants . MinorVersion }
45
46
const maxSpend = util . getMaxSpending ( wallet )
46
- const { formatted : maxSpendFormatted } = util . computeBalance ( maxSpend )
47
+ const { formatted : maxSpendFormatted } = util . computeBalance ( maxSpend . toString ( ) )
47
48
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 ] )
51
50
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 )
55
54
const { isMobile } = useWindowDimensions ( )
56
55
57
56
const { state : otpState } = useOtpState ( )
@@ -60,7 +59,7 @@ const Upgrade = ({ address, onClose }) => {
60
59
const [ stage , setStage ] = useState ( - 1 )
61
60
const { resetWorker, recoverRandomness } = useRandomWorker ( )
62
61
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 } )
64
63
65
64
const doUpgrade = async ( ) => {
66
65
if ( stage >= 0 ) {
@@ -79,7 +78,10 @@ const Upgrade = ({ address, onClose }) => {
79
78
spendingInterval
80
79
} = await api . blockchain . getWallet ( { address, raw : true } )
81
80
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
+ }
83
85
const transformedLastResortAddress = util . isDefaultRecoveryAddress ( lastResortAddress ) ? ONEConstants . TreasuryAddress : lastResortAddress
84
86
const { address : newAddress } = await api . relayer . create ( {
85
87
root,
@@ -101,18 +103,13 @@ const Upgrade = ({ address, onClose }) => {
101
103
otp,
102
104
otp2,
103
105
recoverRandomness,
104
- prepareProofFailed,
105
106
commitHashGenerator : ONE . computeForwardHash ,
106
107
commitHashArgs : { address : newAddress } ,
107
108
beforeCommit : ( ) => setStage ( 1 ) ,
108
109
afterCommit : ( ) => setStage ( 2 ) ,
109
- onCommitError,
110
- onCommitFailure,
111
110
revealAPI : api . relayer . revealForward ,
112
111
revealArgs : { dest : newAddress } ,
113
- onRevealFailure,
114
- onRevealError,
115
- onRevealAttemptFailed,
112
+ ...helpers ,
116
113
onRevealSuccess : async ( txId ) => {
117
114
onRevealSuccess ( txId )
118
115
setStage ( - 1 )
@@ -143,6 +140,10 @@ const Upgrade = ({ address, onClose }) => {
143
140
setSkipUpdate ( true )
144
141
onClose && onClose ( )
145
142
}
143
+ const skipVersion = ( ) => {
144
+ dispatch ( walletActions . userSkipVersion ( { address, version : ONEUtil . getVersion ( latestVersion ) } ) )
145
+ skip ( )
146
+ }
146
147
if ( ! requireUpdate || skipUpdate || ! canUpgrade || temp || ! util . isEmptyAddress ( forwardAddress ) ) {
147
148
return < > </ >
148
149
}
@@ -157,6 +158,8 @@ const Upgrade = ({ address, onClose }) => {
157
158
height : '100%' ,
158
159
justifyContent : 'start' ,
159
160
paddingTop : isMobile ? 32 : 192 ,
161
+ paddingLeft : isMobile ? 16 : 64 ,
162
+ paddingRight : isMobile ? 16 : 64 ,
160
163
display : 'flex'
161
164
} }
162
165
>
@@ -166,37 +169,61 @@ const Upgrade = ({ address, onClose }) => {
166
169
< Text > Your wallet: v{ ONEUtil . getVersion ( wallet ) } </ Text >
167
170
< Text > Latest version: v{ ONEUtil . getVersion ( latestVersion ) } </ Text >
168
171
< 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 >
170
174
< 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 >
171
175
</ > }
172
176
{ confirmUpgradeVisible &&
173
177
< >
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 > }
175
226
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 > }
200
227
</ > }
201
228
{ stage >= 0 && (
202
229
< Row >
0 commit comments