Skip to content

Commit

Permalink
Merge pull request #390 from mysteriumnetwork/fixes/onboarding-paymen…
Browse files Browse the repository at this point in the history
…t-recovery

Proceed to registration if balance is not zero during on-boarding top-up
  • Loading branch information
mdomasevicius committed Aug 26, 2022
2 parents d35c441 + 9c4e98c commit 670a63a
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/app/onboarding/components/InitialTopup/InitialTopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
* LICENSE file in the root directory of this source tree.
*/
import { observer } from "mobx-react-lite"
import React, { useState } from "react"
import React, { useEffect, useState } from "react"
import { faUserFriends, faWallet } from "@fortawesome/free-solid-svg-icons"
import styled from "styled-components"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import Lottie from "react-lottie-player"
import { IdentityRegistrationStatus } from "mysterium-vpn-js"
import BigNumber from "bignumber.js"

import { ViewContainer } from "../../../navigation/components/ViewContainer/ViewContainer"
import { ViewSplit } from "../../../navigation/components/ViewSplit/ViewSplit"
Expand Down Expand Up @@ -65,8 +67,11 @@ const Content = styled(ViewContent)`
justify-content: center;
`

const HALF_MYST = 500_000_000_000_000_000

export const InitialTopup: React.FC = observer(function InitialTopup() {
const { payment, onboarding } = useStores()
const { payment, onboarding, identity, navigation } = useStores()

const handleTopupNow = async () => {
return payment.startTopupFlow(locations.onboardingWalletTopup)
}
Expand All @@ -81,6 +86,24 @@ export const InitialTopup: React.FC = observer(function InitialTopup() {
const handleReferralCancel = () => {
setReferralPrompt(false)
}

useEffect(() => {
const skipToRegistrationIfAlreadyPaid = () => {
const id = identity.identity?.id
const status = identity.identity?.registrationStatus
const balanceWei = identity.identity?.balanceTokens.wei
if (
id &&
status === IdentityRegistrationStatus.Unregistered &&
new BigNumber(balanceWei ?? 0).gte(HALF_MYST)
) {
identity.register(identity.requireId())
navigation.push(locations.idRegistering)
}
}
skipToRegistrationIfAlreadyPaid()
}, [identity.identity?.id])

return (
<ViewContainer>
<ViewNavBar />
Expand Down

0 comments on commit 670a63a

Please sign in to comment.