Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/boba/gateway/src/actions/balanceAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,7 @@ export function fetchL2BalanceBOBA() {
export function fetchUserAndL2LPBalanceBatch(tokenList) {
return createAction('FETCH/USER/L2LP/BALANCE/BATCH', () => networkService.getL2UserAndLPBalanceBatch(tokenList))
}

export function fetchExitFee() {
return createAction('FETCH/EXITFEE', () => networkService.getExitFeeFromBillingContract())
}
5 changes: 4 additions & 1 deletion packages/boba/gateway/src/actions/nftAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ export async function addNFT ( NFT ) {
tokenID: NFT.tokenID,
symbol: NFT.symbol,
url: NFT.url,
meta: NFT.meta
meta: NFT.meta,
account: NFT.account,
network: NFT.network,
layer: NFT.layer
}

store.dispatch({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
selectAccountEnabled,
selectBobaFeeChoice,
selectLayer,
selectBobaPriceRatio,
//selectBobaPriceRatio,
selectNetwork
} from 'selectors/setupSelector'

Expand All @@ -44,7 +44,7 @@ function FeeSwitcher() {
const dispatch = useDispatch()
const accountEnabled = useSelector(selectAccountEnabled())
const feeUseBoba = useSelector(selectBobaFeeChoice())
const feePriceRatio = useSelector(selectBobaPriceRatio())
//const feePriceRatio = useSelector(selectBobaPriceRatio())
const network = useSelector(selectNetwork())

const layer = useSelector(selectLayer())
Expand All @@ -59,8 +59,8 @@ function FeeSwitcher() {

const dispatchSwitchFee = useCallback(async (targetFee) => {

console.log("balanceBOBA:",balanceBOBA)
console.log("balanceETH:",balanceETH)
//console.log("balanceBOBA:",balanceBOBA)
//console.log("balanceETH:",balanceETH)

let tooSmallETH = false
let tooSmallBOBA = false
Expand All @@ -80,7 +80,7 @@ function FeeSwitcher() {
}

if (!balanceBOBA && !balanceETH) {
dispatch(openError('Wallet completely empty - please bridge in ETH or BOBA from L1'))
dispatch(openError('Wallet empty - please bridge in ETH or BOBA from L1'))
return
}

Expand All @@ -95,17 +95,17 @@ function FeeSwitcher() {
else if ( !feeUseBoba && targetFee === 'BOBA' ) {
// change to BOBA
if( tooSmallBOBA ) {
dispatch(openError('You cannot change the fee token to BOBA since your BOBA balance is below 3 BOBA. \
If you change fee token now, you might get stuck. Please swap some ETH for BOBA first.'))
dispatch(openError(`You cannot change the fee token to BOBA since your BOBA balance is below 3 BOBA.
If you change fee token now, you might get stuck. Please swap some ETH for BOBA first.`))
} else {
res = await dispatch(switchFee(targetFee))
}
}
else if (feeUseBoba && targetFee === 'ETH') {
// change to ETH
if( tooSmallETH ) {
dispatch(openError('You cannot change the fee token to ETH since your ETH balance is below 0.002 ETH. \
If you change fee token now, you might get stuck. Please swap some BOBA for ETH first.'))
dispatch(openError(`You cannot change the fee token to ETH since your ETH balance is below 0.002 ETH.
If you change fee token now, you might get stuck. Please swap some BOBA for ETH first.`))
} else {
res = await dispatch(switchFee(targetFee))
}
Expand Down
2 changes: 1 addition & 1 deletion packages/boba/gateway/src/components/select/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import React from 'react';
import { Select as MuiSelect, MenuItem, useTheme } from '@mui/material';
import * as styles from './Select.module.scss';
import * as S from './Select.style';
import { ArrowDropDownCircleOutlined, ArrowDropDownOutlined } from '@mui/icons-material';
import { ArrowDropDownOutlined } from '@mui/icons-material';

function Select ({
label,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ function WalletPicker({

const dispatchBootAccount = useCallback(() => {

console.log("Calling initializeAccount for:", network)
//console.log("Calling initializeAccount for:", network)

if (!accountEnabled) initializeAccount()

async function initializeAccount() {

const initialized = await networkService.initializeAccount(network)
console.log(['initialized',initialized])
//console.log(['initialized',initialized])
if (initialized === 'wrongnetwork') {

dispatch(openModal('wrongNetworkModal'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,18 @@ import parse from 'html-react-parser'

import BN from 'bignumber.js'

import {
import {
fetchClassicExitCost,
fetchL2BalanceETH,
fetchL2BalanceBOBA,
fetchL2BalanceETH,
fetchL2BalanceBOBA,
fetchExitFee,
} from 'actions/balanceAction'

import {
import {
selectClassicExitCost, //estimated total cost of this exit
selectL2BalanceETH,
selectL2BalanceBOBA,
selectExitFee,
} from 'selectors/balanceSelector'

function DoExitStep({ handleClose, token }) {
Expand Down Expand Up @@ -82,25 +84,27 @@ function DoExitStep({ handleClose, token }) {
const feeUseBoba = useSelector(selectBobaFeeChoice())
const feePriceRatio = useSelector(selectBobaPriceRatio())

const exitFee = useSelector(selectExitFee)

function setAmount(value) {

const balance = Number(logAmount(token.balance, token.decimals))

const tooSmall = new BN(value).lte(new BN(0.0))
const tooBig = new BN(value).gt(new BN(max_Float))

setErrorString('')

if (tooSmall || tooBig) {
setErrorString('Warning: Value out of bounds')
setValidValue(false)
setValue(value)
return false
}
}
else if (
!feeUseBoba && // check is needed regardless of fee token choice
token.symbol === 'ETH' &&
(Number(value) + feeETH) > balance)
token.symbol === 'ETH' &&
(Number(value) + feeETH) > balance)
{
// insufficient ETH to cover the ETH amount plus gas
// due to MetaMask issue, this is needed even if you are paying in ETH
Expand All @@ -111,8 +115,8 @@ function DoExitStep({ handleClose, token }) {
}
else if (
feeUseBoba && // check is needed regardless of fee token choice
token.symbol === 'ETH' &&
(Number(value) + feeETH) > balance)
token.symbol === 'ETH' &&
(Number(value) + feeETH) > balance)
{
// insufficient ETH to cover the ETH amount plus gas
// due to MetaMask issue, this is needed even if you are paying in ETH
Expand All @@ -123,8 +127,8 @@ function DoExitStep({ handleClose, token }) {
}
else if (
feeUseBoba &&
token.symbol === 'BOBA' &&
(Number(value) + feeBOBA) > balance)
token.symbol === 'BOBA' &&
(Number(value) + feeBOBA) > balance)
{
// insufficient BOBA to cover the BOBA amount plus gas
setErrorString('Warning: BOBA amount + fees > balance')
Expand All @@ -134,7 +138,7 @@ function DoExitStep({ handleClose, token }) {
}
else if (
!feeUseBoba &&
feeETH > Number(feeBalanceETH))
feeETH > Number(feeBalanceETH))
{
// insufficient ETH to cover exit fees
setErrorString('Warning: ETH balance too low.')
Expand All @@ -144,7 +148,7 @@ function DoExitStep({ handleClose, token }) {
}
else if (
feeUseBoba &&
feeETH > Number(feeBalanceETH))
feeETH > Number(feeBalanceETH))
{
// insufficient ETH to cover exit fees
setErrorString('Warning: ETH balance too low. Even if you pay in BOBA, you still need to maintain a minimum ETH balance in your wallet.')
Expand All @@ -154,7 +158,7 @@ function DoExitStep({ handleClose, token }) {
}
else if (
feeUseBoba &&
feeBOBA > Number(feeBalanceBOBA))
feeBOBA > Number(feeBalanceBOBA))
{
// insufficient BOBA to cover exit fees
setErrorString('Warning: BOBA balance too low')
Expand Down Expand Up @@ -208,13 +212,14 @@ function DoExitStep({ handleClose, token }) {
dispatch(fetchClassicExitCost(token.address))
dispatch(fetchL2BalanceETH())
dispatch(fetchL2BalanceBOBA())
dispatch(fetchExitFee())
}
}, [ token, dispatch ])

useEffect(() => {

function estimateMax() {

const safeCost = Number(cost) * 1.04 // 1.04 = safety margin on the cost
console.log("ETH fees:", safeCost)
console.log("BOBA fees:", safeCost * feePriceRatio)
Expand All @@ -230,13 +235,13 @@ function DoExitStep({ handleClose, token }) {
setMax_Float(balance - safeCost)
else
setMax_Float(0.0)
}
}
else if (token.symbol === 'BOBA' && feeUseBoba) {
if(balance - safeCost > 0.0)
setMax_Float(balance - safeCost)
else
setMax_Float(0.0)
}
}
else {
setMax_Float(balance)
}
Expand All @@ -248,17 +253,17 @@ function DoExitStep({ handleClose, token }) {

if(feeETH && Number(feeETH) > 0) {
if(feeUseBoba) {
ETHstring = `Estimated gas (approval + exit): ${Number(feeBOBA).toFixed(4)} BOBA`
ETHstring = `Estimated gas (approval + exit): ${Number(feeBOBA).toFixed(4)} BOBA`
} else {
ETHstring = `Estimated gas (approval + exit): ${Number(feeETH).toFixed(4)} ETH`
ETHstring = `Estimated gas (approval + exit): ${Number(feeETH).toFixed(4)} ETH`
}
}

// prohibit ExitAll when paying with the token that is to be exited
// prohibit ExitAll when paying with the token that is to be exited
let allowExitall = true
if(token.symbol === 'ETH') {
allowExitall = false
}
}
else if (token.symbol === 'BOBA' && feeUseBoba) {
allowExitall = false
}
Expand All @@ -281,6 +286,7 @@ function DoExitStep({ handleClose, token }) {
setValue_Wei_String(toWei_String(i.target.value, token.decimals))
}}
onUseMax={(i)=>{//they want to use the maximum
console.log(i)
setAmount(max_Float) //so the display value updates for the user
setValue_Wei_String(token.balance.toString())
}}
Expand All @@ -304,11 +310,15 @@ function DoExitStep({ handleClose, token }) {
on L1. Your funds will be available on L1 in 7 days.`}
</Typography>
)}

<Typography variant="body2" sx={{mt: 2}}>
{parse(ETHstring)}
</Typography>


<Typography variant="body2" sx={{mt: 2}}>
{parse(`Exit Fee: ${exitFee} BOBA`)}
</Typography>

{errorString !== '' &&
<Typography variant="body2" sx={{mt: 2, color: 'red'}}>
{errorString}
Expand Down
Loading