Skip to content
Open
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
29 changes: 25 additions & 4 deletions src/components/cards/AppInfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import useApplicationActions from '@/hooks/useApplicationActions'
import useWallet from '@/hooks/useWallet'
import { useAllocator } from '@/lib/AllocatorProvider'
import { stateColor, stateMapping } from '@/lib/constants'
import { getAllowanceForClient } from '@/lib/glifApi'
import {
getAllowanceForClient,
getFilecoinAddressFromEvmAddress,
} from '@/lib/glifApi'
import {
anyToBytes,
bytesToiB,
Expand Down Expand Up @@ -113,7 +116,11 @@ const AppInfoCard: React.FC<ComponentProps> = ({
mutationDecreaseAllowanceProposal,
mutationDecreaseAllowanceApproval,
} = useApplicationActions(initialApplication, repo, owner)
const { getAllowanceFromClientContract } = useWallet()
const {
getAllowanceFromClientContract,
getClientContractAddressFromOnRampContract,
} = useWallet()

const [buttonText, setButtonText] = useState('')
const [modalMessage, setModalMessage] = useState<ReactNode | null>(null)
const [error, setError] = useState<boolean>(false)
Expand Down Expand Up @@ -216,13 +223,26 @@ const AppInfoCard: React.FC<ComponentProps> = ({
const address = application.Lifecycle['On Chain Address']

let clientAllowance

const contractAddress = application['Client Contract Address'] ?? address
const response = await getAllowanceForClient(contractAddress)
if (application['Client Contract Address']) {
let onRampClientContractAddress
const evmOnRampClientContractAddress =
await getClientContractAddressFromOnRampContract(
application['Client Contract Address'],
)
if (evmOnRampClientContractAddress) {
const filecoinOnRampClientContractAddressResult =
await getFilecoinAddressFromEvmAddress(
evmOnRampClientContractAddress,
)
onRampClientContractAddress =
filecoinOnRampClientContractAddressResult.data
}

clientAllowance = await getAllowanceFromClientContract(
address,
application['Client Contract Address'],
onRampClientContractAddress ?? application['Client Contract Address'],
)
}

Expand Down Expand Up @@ -289,6 +309,7 @@ const AppInfoCard: React.FC<ComponentProps> = ({
isApplicationUpdatedLessThanOneMinuteAgo,
getAllowanceFromClientContract,
clientDataCap,
getClientContractAddressFromOnRampContract,
])

useEffect(() => {
Expand Down
47 changes: 41 additions & 6 deletions src/hooks/useApplicationActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from '@/lib/apiClient'
import {
getEvmAddressFromFilecoinAddress,
getFilecoinAddressFromEvmAddress,
getStateWaitMsg,
} from '@/lib/glifApi'
import { config } from '@/config'
Expand Down Expand Up @@ -192,6 +193,7 @@ const useApplicationActions = (
sendClientDecreaseAllowanceProposal,
getDecreaseAllowanceProposalTx,
getAllowanceFromClientContract,
getClientContractAddressFromOnRampContract,
} = useWallet()
const { selectedAllocator } = useAllocator()

Expand Down Expand Up @@ -550,27 +552,45 @@ const useApplicationActions = (
}

let amountOfDataCapSentToContract
let onRampClientContractAddress
if (clientContractAddress && evmClientAddress) {
const evmOnRampClientContractAddress =
await getClientContractAddressFromOnRampContract(
clientContractAddress,
)
if (evmOnRampClientContractAddress) {
const filecoinOnRampClientContractAddressResult =
await getFilecoinAddressFromEvmAddress(
evmOnRampClientContractAddress,
)
onRampClientContractAddress =
filecoinOnRampClientContractAddressResult.data
}

amountOfDataCapSentToContract = await getDataCapToSendToContract(
proposalAllocationAmount,
clientContractAddress,
getAllowanceFromClientContract,
onRampClientContractAddress,
)
}

const proposalTx = await getProposalTx(
clientAddress,
proposalAllocationAmount,
allocatorType,
clientContractAddress,
amountOfDataCapSentToContract,
onRampClientContractAddress,
)
let messageCID
if (amountOfDataCapSentToContract !== null) {
if (proposalTx?.pendingVerifyClientTransaction) {
throw new Error('This datacap allocation is already proposed')
}

const addressToGrantDataCap = clientContractAddress ?? clientAddress
const addressToGrantDataCap =
onRampClientContractAddress ?? clientContractAddress ?? clientAddress

messageCID = await sendProposal({
allocatorType,
Expand Down Expand Up @@ -855,9 +875,22 @@ const useApplicationActions = (

const clientAddress = getClientAddress()

let clientAddressAddress
let clientContractAddress
let onRampClientContractAddress
if (initialApplication['Client Contract Address']) {
clientAddressAddress = initialApplication['Client Contract Address']
clientContractAddress = initialApplication['Client Contract Address']
const evmOnRampClientContractAddress =
await getClientContractAddressFromOnRampContract(
clientContractAddress,
)
if (evmOnRampClientContractAddress) {
const filecoinOnRampClientContractAddressResult =
await getFilecoinAddressFromEvmAddress(
evmOnRampClientContractAddress,
)
onRampClientContractAddress =
filecoinOnRampClientContractAddressResult.data
}
}

const activeRequest = initialApplication['Allocation Requests'].find(
Expand All @@ -872,12 +905,14 @@ const useApplicationActions = (
increaseAllowanceCid?: string
} = {}
let messageCID

const proposalTx = await getProposalTx(
clientAddress,
datacap,
allocatorType,
clientAddressAddress,
clientContractAddress,
activeRequest?.['Amount of Datacap Sent to Contract'],
onRampClientContractAddress,
)
if (activeRequest?.Signers[0]['Message CID']) {
if (!proposalTx?.pendingVerifyClientTransaction) {
Expand Down Expand Up @@ -923,12 +958,12 @@ const useApplicationActions = (

if (
!proposalTx?.pendingIncreaseAllowanceTransaction &&
clientAddressAddress
clientContractAddress
) {
throw new Error(
'This increase allowance is not proposed yet. You may need to wait some time if the proposal was just sent.',
)
} else if (clientAddressAddress) {
} else if (clientContractAddress) {
const increaseMessageCID = await sendApproval(
proposalTx?.pendingIncreaseAllowanceTransaction,
)
Expand Down
Loading