Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIL-364 Update allowed SPs #148

Merged
merged 43 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
95a2f00
FIL-364 Add modal and bussines logic related to max deviation and all…
lukasz-wal Oct 21, 2024
5c731b2
Save progress
lukasz-wal Oct 22, 2024
4e677e9
Merge branch 'main' of https://github.com/filecoin-project/filplus-re…
lukasz-wal Oct 22, 2024
6e54a9c
Saving progress
lukasz-wal Oct 22, 2024
31e654d
Make dynamic client contract address for application
lukasz-wal Oct 22, 2024
5387e3d
Add call to API about providers propose
lukasz-wal Oct 23, 2024
bd3e4a2
Add possibility to approve all pending SP transactions
lukasz-wal Oct 23, 2024
6de1cae
Add minors changes
lukasz-wal Oct 23, 2024
da492ad
Divide allowed and disallowed sps into chunks
lukasz-wal Oct 24, 2024
f0398e4
Cleanup code
lukasz-wal Oct 28, 2024
8e92095
Small changes
lukasz-wal Oct 28, 2024
7f4b65c
Add some small changes
lukasz-wal Oct 28, 2024
238c8b2
Add error handler
lukasz-wal Oct 28, 2024
905edd6
Add info message for checking max deviation transaction
lukasz-wal Oct 28, 2024
14e81fd
Show spinner while calling contracts
lukasz-wal Oct 28, 2024
6db423f
Adjust type to backend data
lukasz-wal Oct 28, 2024
da73dbd
Save the new available allowed SP list instead of only changes
lukasz-wal Oct 29, 2024
552c66d
Chnage messages
lukasz-wal Oct 29, 2024
06fca72
Fix message slash
lukasz-wal Oct 29, 2024
c2fb37b
Change endpoint body
filip-neti Oct 29, 2024
835d1c8
Message issue
lukasz-wal Oct 29, 2024
c33392f
Merge branch 'feature/FIL-364-update-allowed-sps' of https://github.c…
lukasz-wal Oct 29, 2024
7345834
Changes
filip-neti Oct 29, 2024
b9e8cf2
Merge
lukasz-wal Oct 29, 2024
c099148
Get percentage value from string
lukasz-wal Oct 29, 2024
4030558
Chnage gas limit for transactions
lukasz-wal Oct 29, 2024
48b4d33
Remove gas limit after test
lukasz-wal Oct 29, 2024
1282af8
Adjust to backend
lukasz-wal Oct 29, 2024
b269260
Add spinner while making transactions
lukasz-wal Oct 29, 2024
b206fb2
After test
lukasz-wal Oct 29, 2024
9ebc03f
Some fixes
lukasz-wal Oct 29, 2024
8bda34e
Add info
lukasz-wal Oct 30, 2024
8270a93
Fixes
filip-neti Oct 30, 2024
621f9f6
Change info message textes
lukasz-wal Oct 30, 2024
0cab316
Fix eslint
lukasz-wal Oct 30, 2024
4ecedce
Show connect ledger when state is granted
lukasz-wal Oct 30, 2024
c3ba134
Undo commented code for dev env
lukasz-wal Oct 30, 2024
ce397e6
Merge branch 'main' of https://github.com/filecoin-project/filplus-re…
lukasz-wal Oct 30, 2024
2b4e1b5
Merge changes
lukasz-wal Oct 30, 2024
6f4c943
Update src/hooks/useWallet.ts
lukasz-wal Oct 30, 2024
0cdd13b
Update src/hooks/useWallet.ts
lukasz-wal Oct 30, 2024
258ce81
Update src/hooks/useApplicationActions.ts
lukasz-wal Oct 30, 2024
b03ac73
Update src/hooks/useWallet.ts
lukasz-wal Oct 30, 2024
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
34 changes: 34 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@fontsource/roboto": "^5.0.12",
"@glif/filecoin-address": "^3.0.4",
"@ledgerhq/hw-transport-webusb": "^6.27.19",
"@mui/icons-material": "^5.15.14",
"@mui/material": "^5.15.14",
"@radix-ui/react-avatar": "^1.0.3",
"@radix-ui/react-dialog": "^1.0.5",
Expand Down
180 changes: 152 additions & 28 deletions src/components/cards/AppInfoCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
} from 'react'
import { toast } from 'react-toastify'
import AllocatorBalance from '../AllocatorBalance'
import AllowedSps from './dialogs/allowedSps'

interface ComponentProps {
application: Application
Expand Down Expand Up @@ -100,7 +101,10 @@ const AppInfoCard: React.FC<ComponentProps> = ({
loadMoreAccounts,
mutationRequestKyc,
mutationRemovePendingAllocation,
mutationChangeAllowedSPs,
mutationChangeAllowedSPsApproval,
} = useApplicationActions(initialApplication, repo, owner)

const [buttonText, setButtonText] = useState('')
const [modalMessage, setModalMessage] = useState<ReactNode | null>(null)
const [error, setError] = useState<boolean>(false)
Expand Down Expand Up @@ -340,7 +344,7 @@ const AppInfoCard: React.FC<ComponentProps> = ({
return
}

if (isApiCalling) {
if (isApiCalling && application.Lifecycle.State !== 'ChangingSp') {
setButtonText('Processing...')
return
}
Expand Down Expand Up @@ -813,6 +817,87 @@ const AppInfoCard: React.FC<ComponentProps> = ({
setApiCalling(false)
}

const handleAllowedSPsSubmit = async (
client: string,
clientContractAddress: string,
addedSPs: string[],
removedSPs: string[],
newAvailableResult: string[],
maxDeviation?: string,
): Promise<void> => {
try {
setApiCalling(true)
const requestId = application['Allocation Requests'].find(
(alloc) => alloc.Active,
)?.ID

const userName = session.data?.user?.githubUsername

if (
application.Lifecycle.State === 'ReadyToSign' &&
requestId &&
userName
) {
await mutationChangeAllowedSPs.mutateAsync({
userName,
clientAddress: client,
contractAddress: clientContractAddress,
allowedSps: addedSPs,
disallowedSPs: removedSPs,
newAvailableResult,
maxDeviation,
})
}
} catch (error) {
console.log(error)
handleMutationError(error as Error)
} finally {
setApiCalling(false)
}
}

const handleApproveAllowedSPs = async (): Promise<void> => {
try {
setApiCalling(true)

const activeRequest = application[
'Storage Providers Change Requests'
].find((requests) => requests.Active)

const userName = session.data?.user?.githubUsername

if (activeRequest?.ID != null && userName != null) {
const res = await mutationChangeAllowedSPsApproval.mutateAsync({
activeRequest,
userName,
})

if (res) {
const lastDatacapAllocation = getLastDatacapAllocation(res)
if (lastDatacapAllocation === undefined) {
throw new Error('No datacap allocation found')
}
const queryParams = [
`client=${encodeURIComponent(res?.Client.Name)}`,
`messageCID=${encodeURIComponent(
lastDatacapAllocation.Signers[1]['Message CID'],
)}`,
`amount=${encodeURIComponent(
lastDatacapAllocation['Allocation Amount'],
)}`,
`notification=true`,
].join('&')

router.push(`/?${queryParams}`)
}
}
} catch (error) {
handleMutationError(error as Error)
} finally {
setApiCalling(false)
}
}

return (
<>
<AccountSelectionDialog
Expand Down Expand Up @@ -841,21 +926,18 @@ const AppInfoCard: React.FC<ComponentProps> = ({
</span>
</a>
</div>

{modalMessage != null && (
<Modal
message={modalMessage}
onClose={handleCloseModal}
error={error}
/>
)}

{(isApiCalling || isWalletConnecting) && (
<div className="fixed inset-0 flex items-center justify-center z-50 bg-black bg-opacity-50">
<Spinner />
</div>
)}

<Card className="bg-gray-50 p-4 rounded-lg shadow-lg">
<div className="flex flex-col lg:flex-row gap-4">
<div className="flex-1">
Expand Down Expand Up @@ -954,6 +1036,72 @@ const AppInfoCard: React.FC<ComponentProps> = ({
<AllocatorBalance owner={owner} repo={repo} />
</div>
<div className="flex justify-end gap-2 pb-4">
{LDNActorType.Verifier === currentActorType &&
walletConnected &&
session?.data?.user?.name !== undefined &&
application?.Lifecycle?.['On Chain Address'] &&
application?.['Client Contract Address'] &&
['ReadyToSign', 'Granted'].includes(
application?.Lifecycle?.State,
) && (
<div className="flex gap-2">
<AllowedSps
onSubmit={handleAllowedSPsSubmit}
client={application.Lifecycle['On Chain Address']}
clientContractAddress={
application['Client Contract Address']
}
initDeviation="10"
isApiCalling={isApiCalling}
setApiCalling={setApiCalling}
/>
</div>
)}

{!walletConnected &&
currentActorType === LDNActorType.Verifier &&
![
'KYCRequested',
'Submitted',
'ChangesRequested',
'AdditionalInfoRequired',
'AdditionalInfoSubmitted',
].includes(application?.Lifecycle?.State) && (
<Button
onClick={() => void handleConnectLedger()}
disabled={
isWalletConnecting ||
isApiCalling ||
['Submitted'].includes(application.Lifecycle.State)
}
className="bg-blue-500 text-white rounded-lg px-4 py-2 hover:bg-blue-600"
>
Connect Ledger
</Button>
)}

{LDNActorType.Verifier === currentActorType &&
walletConnected &&
session?.data?.user?.name !== undefined &&
application?.Lifecycle?.['On Chain Address'] &&
application?.['Client Contract Address'] &&
['ChangingSP'].includes(application?.Lifecycle?.State) && (
<div className="flex gap-2">
<Button
onClick={() => {
void handleApproveAllowedSPs()
}}
disabled={isApiCalling}
style={{
width: '250px',
}}
className="bg-green-400 text-black rounded-lg px-4 py-2 hover:bg-green-500"
>
Approve SP Propose
</Button>
</div>
)}

{LDNActorType.Verifier === currentActorType ? (
session?.data?.user?.name !== undefined &&
application?.Lifecycle?.State !== 'Granted' ? (
Expand Down Expand Up @@ -1048,30 +1196,6 @@ const AppInfoCard: React.FC<ComponentProps> = ({
</Button>
</>
)}

{!walletConnected &&
currentActorType === LDNActorType.Verifier &&
![
'KYCRequested',
'Submitted',
'ChangesRequested',
'AdditionalInfoRequired',
'AdditionalInfoSubmitted',
].includes(application?.Lifecycle?.State) && (
<Button
onClick={() => void handleConnectLedger()}
disabled={
isWalletConnecting ||
isApiCalling ||
['Granted', 'Submitted'].includes(
application.Lifecycle.State,
)
}
className="bg-blue-500 text-white rounded-lg px-4 py-2 hover:bg-blue-600"
>
Connect Ledger
</Button>
)}
</>
) : (
progress > 75 &&
Expand Down
Loading