Skip to content

Commit

Permalink
Merge pull request #497 from bobanetwork/main
Browse files Browse the repository at this point in the history
Patch Release Gateway!
  • Loading branch information
sk-enya authored Apr 24, 2024
2 parents 5582dfb + 72530b9 commit 4560868
Show file tree
Hide file tree
Showing 32 changed files with 136 additions and 65 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bobanetwork/gateway",
"version": "0.14.5",
"version": "0.14.6",
"private": true,
"scripts": {
"audit-check": "audit-ci --moderate",
Expand Down
7 changes: 7 additions & 0 deletions src/actions/bridgeAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ export const setTeleportationOfAssetSupported =
payload,
})

export const setTeleportationDisburserBalance =
(payload: string) => (dispatch) =>
dispatch({
type: 'BRIDGE/TELEPORTER/DISBURSER_BALANCE',
payload,
})

export const setTeleportationDestChainId =
(payload: BigNumberish) => (dispatch) =>
dispatch({
Expand Down
5 changes: 5 additions & 0 deletions src/actions/networkAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ export const isTeleportationOfAssetSupported = (
networkService.isTeleportationOfAssetSupported(layer, asset, destChainId)
)

export const getDisburserBalance = (layer: string, asset: string) =>
createAction('DEPOSIT/TELEPORTATION/DISBURSER_BALANCE', () =>
networkService.getNativeDisburserBalance(layer, asset)
)

export const depositWithLightBridge = (
layer: string,
currency: string,
Expand Down
30 changes: 16 additions & 14 deletions src/actions/uiAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,30 @@ export const setTheme =
(dispatch) =>
dispatch({ type: 'UI/THEME/UPDATE', payload: theme })

interface IOpenModalProps {
modal?: string
proposalId?: any
selectionLayer?: any
destNetworkSelection?: any
isNewTx?: Boolean
}

export const openModal =
(
modal?,
token?,
fast?,
tokenIndex?,
lock?,
proposalId?,
selectionLayer?,
destNetworkSelection?
): any =>
({
modal,
proposalId,
selectionLayer,
destNetworkSelection,
isNewTx,
}: IOpenModalProps): any =>
(dispatch) =>
dispatch({
type: 'UI/MODAL/OPEN',
payload: modal,
token,
fast,
tokenIndex,
lock,
proposalId,
selectionLayer,
destNetworkSelection,
isNewTx,
})

export const closeModal =
Expand Down
2 changes: 1 addition & 1 deletion src/components/listProposal/listProposal.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const ListProposal = ({ proposal }) => {
}, [proposal])

const onVote = (id) => {
dispatch(openModal('castVoteModal', null, null, null, null, id))
dispatch(openModal({modal: 'castVoteModal',proposalId: id}))
}

const doQueueProposal = async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Bridging/BridgeAction/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const BridgeAction = () => {

const onBridge = () => {
if (!isBridgeActionDisabled()) {
dispatch(openModal('bridgeConfirmModal'))
dispatch(openModal({ modal: 'bridgeConfirmModal' }))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/containers/Bridging/BridgeHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const BridgeHeader = () => {
theme.name === 'light' ? theme.colors.gray[600] : theme.colors.gray[100]

const openSettingModal = () => {
dispatch(openModal('settingsModal'))
dispatch(openModal({ modal: 'settingsModal' }))
}

// TODO: update the copy when the anchorage bridge is enabled.
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Bridging/BridgeInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const BridgeInput: FC<Props> = (props) => {
useBridgeSetup()

const openTokenPicker = () => {
dispatch(openModal('tokenPicker'))
dispatch(openModal({ modal: 'tokenPicker' }))
}

if (!isAccountEnabled) {
Expand Down
15 changes: 5 additions & 10 deletions src/containers/Bridging/chain/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,11 @@ const Chains = (props: Props) => {
sLayer = inputLayer === 'l1' ? 'l2' : 'l1'
}
dispatch(
openModal(
'networkPicker',
null,
null,
null,
null,
null,
sLayer,
destNetworkSelection
)
openModal({
modal: 'networkPicker',
selectionLayer: sLayer,
destNetworkSelection,
})
)
}

Expand Down
7 changes: 6 additions & 1 deletion src/containers/Bridging/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ const Bridging = () => {
state={reenterWithdrawConfig?.state}
onReenterWithdrawal={() => {
dispatch(setReenterWithdrawalConfig(reenterWithdrawConfig))
dispatch(openModal('bridgeMultiStepWithdrawal'))
dispatch(
openModal({
modal: 'bridgeMultiStepWithdrawal',
isNewTx: false,
})
)
}}
/>
)}
Expand Down
4 changes: 2 additions & 2 deletions src/containers/dao/OldDao.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const OldDao = () => {
)
)
} else {
dispatch(openModal('newProposalModal'))
dispatch(openModal({modal: 'newProposalModal'}))
}
}

Expand Down Expand Up @@ -175,7 +175,7 @@ const OldDao = () => {
<S.DaoWalletAction>
<Button
onClick={() => {
dispatch(openModal('delegateDaoModal'))
dispatch(openModal({modal: 'delegateDaoModal'}))
}}
disabled={!(Number(balance) + Number(balanceX))}
label="Delegate Vote"
Expand Down
2 changes: 1 addition & 1 deletion src/containers/earn/earnList/earnListItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const EarnListItem = ({
decimals: poolInfo.decimals,
})
)
dispatch(openModal('EarnWithdrawModal'))
dispatch(openModal({ modal: 'EarnWithdrawModal' }))
}

let enableReward = false
Expand Down
4 changes: 3 additions & 1 deletion src/containers/history/TransactionsResolver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ export const TransactionsResolver: React.FC<ITransactionsResolverProps> = ({
switch (transaction.actionRequired.type) {
case 'reenterWithdraw': {
dispatch(setReenterWithdrawalConfig(transaction.actionRequired))
dispatch(openModal('bridgeMultiStepWithdrawal'))
dispatch(
openModal({ modal: 'bridgeMultiStepWithdrawal', isNewTx: false })
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
interface IVerticalStepperProps {
handleClose: () => void
token?: any
amountToBridge?: number
amountToBridge: number
reenterWithdrawConfig?: any
}

Expand Down Expand Up @@ -92,7 +92,9 @@ export const VerticalStepper = (props: IVerticalStepperProps) => {
handleInitiateWithdrawal(
networkService as MinimalNetworkService,
L2StandardERC20ABI,
ethers.utils.parseEther(props.amountToBridge!.toString()).toString(),
ethers.utils
.parseUnits(props.amountToBridge!.toString(), props.token.decimals)
.toString(),
isNativeWithdrawal ? null : props.token
)
.then((res) => {
Expand Down Expand Up @@ -148,7 +150,7 @@ export const VerticalStepper = (props: IVerticalStepperProps) => {
latestLogs
).then(() => {
dispatch(closeModal('bridgeMultiStepWithdrawal'))
dispatch(openModal('transactionSuccess'))
dispatch(openModal({ modal: 'transactionSuccess' }))
setLoading(false)
})
} else {
Expand All @@ -164,7 +166,7 @@ export const VerticalStepper = (props: IVerticalStepperProps) => {
claimWithdrawal(networkService as MinimalNetworkService, logs).then(
() => {
setActiveStep(6)
dispatch(openModal('transactionSuccess'))
dispatch(openModal({ modal: 'transactionSuccess' }))
dispatch(closeModal('bridgeMultiStepWithdrawal'))
setLoading(false)
}
Expand Down
11 changes: 6 additions & 5 deletions src/containers/modals/MultiStepWithdrawalModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ import { utils } from 'ethers'
import { TokenInfo } from 'containers/history/tokenInfo'

interface Props {
open: boolean
open: Boolean
isNewTx: Boolean
}

export const MultiStepWithdrawalModal: FC<Props> = ({ open }) => {
export const MultiStepWithdrawalModal: FC<Props> = ({ open, isNewTx }) => {
const withdrawalConfig = useSelector(selectReenterWithdrawalConfig())
const dispatch = useDispatch<any>()
const _token = useSelector(selectTokenToBridge()) // is undefined on network change
Expand All @@ -54,7 +55,7 @@ export const MultiStepWithdrawalModal: FC<Props> = ({ open }) => {
setAmountToBridge(_amountToBridge)
}

if (withdrawalConfig && withdrawalConfig.amount) {
if (!isNewTx && withdrawalConfig && withdrawalConfig.amount) {
const token =
TokenInfo[withdrawalConfig.originChainId.toString()]?.[
withdrawalConfig.token?.toLowerCase()
Expand All @@ -63,7 +64,7 @@ export const MultiStepWithdrawalModal: FC<Props> = ({ open }) => {
setAmountToBridge(utils.formatEther(amount))
setToken({ ...token, address: withdrawalConfig.token })
}
}, [_token, _amountToBridge, withdrawalConfig])
}, [_token, _amountToBridge, withdrawalConfig, isNewTx])

const handleClose = () => {
dispatch(setReenterWithdrawalConfig(null))
Expand Down Expand Up @@ -104,7 +105,7 @@ export const MultiStepWithdrawalModal: FC<Props> = ({ open }) => {
<Separator />

<VerticalStepper
reenterWithdrawConfig={withdrawalConfig}
reenterWithdrawConfig={isNewTx ? null : withdrawalConfig}
handleClose={handleClose}
token={token}
amountToBridge={amountToBridge}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const EarnWithdrawConfirmModal = ({ open }: EarnWithdrawConfirmModalProps) => {
)

if (withdrawLiquidityTX) {
dispatch(openModal('EarnWithdrawModalSuccess'))
dispatch(openModal({ modal: 'EarnWithdrawModalSuccess' }))
dispatch(getEarnInfo())
} else {
dispatch(openError(`Failed to withdraw ${withdrawPayload.symbol}`))
Expand Down
2 changes: 1 addition & 1 deletion src/containers/modals/earn/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ const EarnWithdrawModal = ({ open }: EarnWithdrwaModalProps) => {
)

dispatch(closeModal('EarnWithdrawModal'))
dispatch(openModal('EarnWithdrawConfirmModal'))
dispatch(openModal({ modal: 'EarnWithdrawConfirmModal' }))
}

const setAmount = (userEnteredValue: any, userEnteredValueInWei: string) => {
Expand Down
12 changes: 6 additions & 6 deletions src/containers/modals/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import CastVoteModal from './DaoModals/CastVoteModal'
import NewProposalModal from './DaoModals/NewProposalModal'
import DelegateDaoModal from './DaoModals/DelegateDaoModal'

// import EarnWithdrawModal from './earn/EarnWithdrawModal'
import EarnWithdrawModal from './earn'
import EarnWithdrawConfirmModal from './earn/EarnWithdrawConfirmModal'
import EarnWithdrawModalSuccessModal from './earn/EarnWithdrawSuccess'
Expand Down Expand Up @@ -58,11 +57,7 @@ const ModalContainer = () => {
selectModalState('switchNetworkModal')
)
const SettingsModalState = useSelector(selectModalState('settingsModal'))

const fast = useSelector(selectModalState('fast'))
const token = useSelector(selectModalState('token'))
const tokenIndex = useSelector(selectModalState('tokenIndex'))
const lock = useSelector(selectModalState('lock'))
const proposalId = useSelector(selectModalState('proposalId'))
const destNetworkSelection = useSelector(
selectModalState('destNetworkSelection')
Expand Down Expand Up @@ -95,6 +90,8 @@ const ModalContainer = () => {
selectModalState('bridgeMultiStepWithdrawal')
)

const isNewTx = useSelector(selectModalState('isNewTx'))

const bridgeInProgressModalState = useSelector(
selectModalState('bridgeInProgress')
)
Expand Down Expand Up @@ -168,7 +165,10 @@ const ModalContainer = () => {
)}

{!!bridgeMultiStepModalState && (
<MultiStepWithdrawalModal open={bridgeMultiStepModalState} />
<MultiStepWithdrawalModal
open={bridgeMultiStepModalState}
isNewTx={isNewTx}
/>
)}

{!!bridgeInProgressModalState && (
Expand Down
2 changes: 1 addition & 1 deletion src/containers/modals/noMetaMask/NoMetaMaskModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const NoMetaMaskModal: React.FC<ModalInterface> = ({ open }) => {

const handleAddMetaMask = () => {
window.open(MM_EXTENTION_URL, '_blank')
dispatch(openModal('installMetaMaskModal'))
dispatch(openModal({ modal: 'installMetaMaskModal' }))
handleClose()
}

Expand Down
6 changes: 6 additions & 0 deletions src/containers/modals/tokenPicker/TokenPickerModal.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import React, { FC, useEffect, useState } from 'react'
import {
setTeleportationOfAssetSupported,
setTeleportationDisburserBalance,
updateToken,
} from 'actions/bridgeAction'
import {
fetchBalances,
getDisburserBalance,
isTeleportationOfAssetSupported,
} from 'actions/networkAction'
import { closeModal } from 'actions/uiAction'
Expand Down Expand Up @@ -146,7 +148,11 @@ const TokenPickerModal: FC<TokenPickerModalProps> = ({ open, tokenIndex }) => {
const isSupported = await dispatch(
isTeleportationOfAssetSupported(layer, token.address, destChainId)
)
const disburserBalance = await dispatch(
getDisburserBalance(layer, token.address)
)
dispatch(setTeleportationOfAssetSupported(isSupported))
dispatch(setTeleportationDisburserBalance(disburserBalance))
}
handleClose()
}
Expand Down
4 changes: 3 additions & 1 deletion src/containers/save/Save.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ const Save = () => {
label="Stake"
style={{ width: '100%' }}
disabled={!Boolean(state.max_Float_String !== '0.0')}
onClick={() => dispatch(openModal('StakeDepositModal'))}
onClick={() =>
dispatch(openModal({ modal: 'StakeDepositModal' }))
}
/>
</div>
)}
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useBridge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export const useBridge = () => {
const triggerExit = async (amountWei: any) => {
// As anchorage is release to mainnet & sepolia supports 2 step bridging.
if (!!isAnchorageEnabled) {
dispatch(openModal('bridgeMultiStepWithdrawal'))
dispatch(openModal({ modal: 'bridgeMultiStepWithdrawal', isNewTx: true }))
} else {
return dispatch(exitBOBA(token.address, amountWei))
}
Expand All @@ -181,7 +181,7 @@ export const useBridge = () => {
const amountWei = toWei_String(amountToBridge, token.decimals)

let receipt
dispatch(openModal('bridgeInProgress'))
dispatch(openModal({ modal: 'bridgeInProgress' }))
if (layer === LAYER.L1) {
if (bridgeType === BRIDGE_TYPE.CLASSIC) {
receipt = await triggerDeposit(amountWei)
Expand All @@ -202,7 +202,7 @@ export const useBridge = () => {
}
dispatch(closeModal('bridgeInProgress'))
if (receipt) {
dispatch(openModal('transactionSuccess'))
dispatch(openModal({ modal: 'transactionSuccess' }))
dispatch(resetToken())
dispatch(purgeBridgeAlert())
dispatch(resetBridgeAmount())
Expand Down
Loading

0 comments on commit 4560868

Please sign in to comment.