Skip to content

Commit

Permalink
fix: setIsDeploying not exist and being used
Browse files Browse the repository at this point in the history
  • Loading branch information
TravellerOnTheRun committed Nov 1, 2023
1 parent effe0dc commit fdee005
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 48 deletions.
6 changes: 3 additions & 3 deletions src/screens/accounts/AccountsScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMemo, useEffect, useContext } from 'react'
import { useMemo, useEffect } from 'react'
import { View } from 'react-native'

import { shortAddress } from 'lib/utils'
Expand All @@ -12,12 +12,12 @@ import {
settingsStackRouteNames,
} from 'navigation/settingsNavigator/types'
import { sharedStyles } from 'shared/constants'
import { WalletContext } from 'shared/wallet'
import { useWalletState } from 'shared/wallet'

export const AccountsScreen = ({
navigation,
}: SettingsScreenProps<settingsStackRouteNames.AccountsScreen>) => {
const { wallet, walletIsDeployed } = useContext(WalletContext)
const { wallet, walletIsDeployed } = useWalletState()

const chainId = useAppSelector(selectChainId)
const bitcoinCore = useAppSelector(selectBitcoin)
Expand Down
96 changes: 51 additions & 45 deletions src/screens/settings/RelayDeployScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@ import { useCallback, useEffect, useState } from 'react'
import { Image, StyleSheet, View } from 'react-native'
import { ScrollView } from 'react-native-gesture-handler'
import { BigNumber } from 'ethers'
import {
TransactionResponse,
TransactionReceipt,
} from '@ethersproject/abstract-provider'
import { useTranslation } from 'react-i18next'

import { AppButton, Typography, AppSpinner } from 'components/index'
import { selectChainId, setIsDeploying } from 'store/slices/settingsSlice'
import { useAppDispatch, useAppSelector } from 'store/storeUtils'
import { selectChainId } from 'store/slices/settingsSlice'
import { useAppSelector } from 'store/storeUtils'
import { ChainTypeEnum } from 'store/slices/settingsSlice/types'
import { getTokenAddress } from 'core/config'
import { sharedColors, sharedStyles } from 'shared/constants'
Expand All @@ -35,63 +31,73 @@ export const RelayDeployScreen = ({
const chainId = useAppSelector(selectChainId)
const { loading, isDeployed, txHash } = walletIsDeployed
const { t } = useTranslation()
const dispatch = useAppDispatch()
const [deployError, setDeployError] = useState<string | null>(null)
const updateErrorState = useCallback((error: string | null) => {
setDeployError(error)
}, [])

const deploy = useCallback(async () => {
updateErrorState(null)
setWalletIsDeployed(prev => {
return prev && { ...prev, loading: true }
})
const freePayment = {
tokenContract: getTokenAddress(
chainTypesById[chainId] === ChainTypeEnum.MAINNET ? 'RIF' : 'tRIF',
chainTypesById[chainId],
),
tokenAmount: BigNumber.from(0),
}
try {
updateErrorState(null)
setWalletIsDeployed(prev => {
return prev && { ...prev, loading: true }
})

const freePayment = {
tokenContract: getTokenAddress(
chainTypesById[chainId] === ChainTypeEnum.MAINNET ? 'RIF' : 'tRIF',
chainTypesById[chainId],
),
tokenAmount: BigNumber.from(0),
}

const result = await wallet.deploySmartWallet(freePayment)

setWalletIsDeployed(prev => {
return (
prev && {
...prev,
txHash: result.hash,
}
)
})

const receipt = await result.wait()

wallet
.deploySmartWallet(freePayment)
.then((result: TransactionResponse) => {
if (receipt.status) {
setWalletIsDeployed(prev => {
return (
prev && {
...prev,
txHash: result.hash,
isDeployed: true,
}
)
})

result.wait().then((receipt: TransactionReceipt) => {
if (receipt.status) {
setWalletIsDeployed(prev => {
return (
prev && {
...prev,
isDeployed: true,
}
)
})
} else {
console.log('Deploy Error,', receipt)
updateErrorState(t('wallet_deploy_error'))
} else {
console.log('Deploy Error,', receipt)
updateErrorState(t('wallet_deploy_error'))
}
setWalletIsDeployed(prev => {
return (
prev && {
...prev,
loading: false,
}
dispatch(
setIsDeploying({ address: wallet.address, isDeploying: false }),
)
})
)
})
.catch((error: Error) => {
updateErrorState(error.toString())
dispatch(
setIsDeploying({ address: wallet.address, isDeploying: false }),
} catch (error) {
console.log('DEPLOY FAILED', error)
updateErrorState(error.toString())
setWalletIsDeployed(prev => {
return (
prev && {
...prev,
loading: false,
}
)
})
}, [dispatch, updateErrorState, wallet, t, chainId, setWalletIsDeployed])
}
}, [updateErrorState, wallet, t, chainId, setWalletIsDeployed])

useEffect(() => {
if (backScreen) {
Expand Down

0 comments on commit fdee005

Please sign in to comment.