Skip to content

Commit 42a1382

Browse files
authored
Merge pull request #6520 from blockchain/feat/move-over-old-reversions
Feat/move over old reversions
2 parents 85f2bc4 + c5675c6 commit 42a1382

File tree

1 file changed

+12
-65
lines changed
  • packages/blockchain-wallet-v4-frontend/src/scenes

1 file changed

+12
-65
lines changed

packages/blockchain-wallet-v4-frontend/src/scenes/app.tsx

Lines changed: 12 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -179,37 +179,14 @@ const App = ({
179179
const cookies = new Cookies()
180180
const optOut = localStorage.getItem('opt_out_wallet_v5_ui')
181181
const optOutDate = localStorage.getItem('opt_out_date')
182-
const cache = {
183-
canary_position: cookies.get('canary_position'),
184-
opt_out_wallet_v5_ui: cookies.get('opt_out_wallet_v5_ui')
185-
}
186-
187-
// Update localStorage cache with current values, if exists.
188-
if (localStorage.getItem('canary_position') === null && cache.canary_position) {
189-
localStorage.setItem('canary_position', `${cache.canary_position}`)
190-
}
182+
const optOutDataAsDateObject = optOutDate ? new Date(optOutDate) : new Date() // date user has for their opt out time
183+
const optOutDateThreshold = new Date('2024-11-25T00:00:00.000Z') // cutoff date any user with reversion date before this will go to v5 Nov 22nd 2024
184+
const isOptOutDateAfterDateThreshold = optOutDataAsDateObject > optOutDateThreshold // if user's reversion date is after cutoff this is true, they will stay on v4
191185

192-
// Update localStorage cache with current values, if exists.
193-
if (optOut === null && cache.opt_out_wallet_v5_ui) {
194-
localStorage.setItem('opt_out_wallet_v5_ui', JSON.stringify(cache.opt_out_wallet_v5_ui))
195-
}
196-
197-
if (optOut && optOutDate === null) {
186+
//if opted out and no opt out date add one
187+
if (optOut && optOutDate === null)
198188
localStorage.setItem('opt_out_date', new Date().toISOString())
199-
}
200-
201-
// OBTAIN THE THRESHOLD - STATICALLY SET, DECIDED BY TEAM.
202-
const THRESHOLD = 100
203189

204-
// THE DYNAMIC ROUTING IS DISABLED, SEND TO V4
205-
// @ts-ignore
206-
if (THRESHOLD === 0) {
207-
localStorage.setItem('wallet_v5_ui_available', 'false')
208-
// eslint-disable-next-line
209-
console.log('[ROUTING_DEBUG]: Threshold was not set, assuming v5 is disabled.')
210-
setDynamicRoutingState(false)
211-
return
212-
}
213190
let fullPath: string
214191
if (window.location.hash && window.location.hash !== '#/') {
215192
// OBTAIN FULL PATH BY COMBINING PATHNAME AND HASH (CLIENT-ONLY ROUTING)
@@ -248,47 +225,19 @@ const App = ({
248225
return
249226
}
250227

251-
// OBTAIN THE CANARY POSITION
252-
const canaryPositionString = localStorage.getItem('canary_position')
253-
let canaryPosition = Number(canaryPositionString)
254-
255-
const setCanaryPosition = () => {
256-
canaryPosition = Math.floor(Math.random() * 101)
257-
localStorage.setItem('canary_position', `${canaryPosition}`)
258-
}
259-
260-
// IF THE CANARY POSITION DOES NOT EXIST, GENERATE A NEW ONE.
261-
if (canaryPositionString === null || canaryPositionString === undefined) setCanaryPosition()
262-
263-
// MAKE SURE THE CANARY POSITION IS VALID, IF NOT, UPDATE THE VALUE.
264-
if (Number.isNaN(canaryPosition)) {
228+
// USER HAS SPECIFICALLY REQUESTED TO STAY ON V4.
229+
if (optOut && isOptOutDateAfterDateThreshold) {
265230
// eslint-disable-next-line
266231
console.log(
267-
`[ROUTING_DEBUG]: canary_position was NaN, Raw: ${canaryPositionString}, Setting a new canary_position.`
232+
'[ROUTING_DEBUG]: User has opted out of v5, and their opt out date is after the threshold, staying on v4'
268233
)
269-
setCanaryPosition()
270-
// eslint-disable-next-line
271-
console.log(`[ROUTING_DEBUG]: Set canary_position to ${canaryPosition}`)
272-
}
273-
274-
// IF THE USER HAS REQUESTED TO STAY IN V4.
275-
const reversionRequested = localStorage.getItem('opt_out_wallet_v5_ui') === 'true'
276-
const availableUI = canaryPosition <= THRESHOLD
277-
278-
// USER HAS SPECIFICALLY REQUESTED TO STAY ON V4.
279-
if (reversionRequested) {
280-
localStorage.setItem('wallet_v5_ui_available', availableUI ? 'true' : 'false')
281-
// eslint-disable-next-line
282-
console.log('[ROUTING_DEBUG]: User has opted out of v5, staying on v4')
283234
setDynamicRoutingState(false)
284235
return
285-
}
286-
287-
// RATHER OR NOT V5 IS AVAILABLE
288-
localStorage.setItem('wallet_v5_ui_available', availableUI ? 'true' : 'false')
289-
290-
if (availableUI) {
236+
} else {
291237
const redirectUrl = removeHash(fullPath)
238+
if (optOut) localStorage.removeItem('opt_out_wallet_v5_ui') // go ahead remove opt_out key
239+
if (optOutDate) localStorage.removeItem('opt_out_date') // remove user's old opt out date
240+
292241
// eslint-disable-next-line
293242
console.log('xx', 'Redirecting to v5', redirectUrl)
294243
// Using **WALLET_V5_LINK** as a fallback for webpack builder.
@@ -304,8 +253,6 @@ const App = ({
304253

305254
return
306255
}
307-
308-
setDynamicRoutingState(false)
309256
}, [])
310257

311258
// parse and log UTMs

0 commit comments

Comments
 (0)