Skip to content

Commit

Permalink
do not clear project index, metadata until removal is approved
Browse files Browse the repository at this point in the history
  • Loading branch information
yuetloo committed Jul 13, 2023
1 parent 67899c6 commit 36ae4ac
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 19 deletions.
41 changes: 30 additions & 11 deletions subgraph/src/OptimisticRecipientRegistryMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,36 @@ export function handleRequestSubmitted(event: RequestSubmitted): void {
//TODO: create RecipientRegistry entity here if it does not exist.

let recipientId = event.params._recipientId.toHexString()
let recipient = new Recipient(recipientId)

recipient.recipientRegistry = recipientRegistryId
recipient.recipientAddress = event.params._recipient
recipient.requestType = BigInt.fromI32(event.params._type).toString()
recipient.requester = event.transaction.from.toHexString()
recipient.submissionTime = event.params._timestamp.toString()
recipient.deposit = event.transaction.value
recipient.recipientMetadata = event.params._metadata
recipient.verified = false
recipient.requestSubmittedHash = event.transaction.hash
if (event.params._type == 0) {
// add recipient request
let recipient = new Recipient(recipientId)
recipient.recipientRegistry = recipientRegistryId
recipient.recipientAddress = event.params._recipient
recipient.requester = event.transaction.from.toHexString()
recipient.deposit = event.transaction.value
recipient.recipientMetadata = event.params._metadata

recipient.save()
// requestSubmittedHash stores the transaction hash for add recipient request
// the UI uses it to look up the newly added recipient record
recipient.requestSubmittedHash = event.transaction.hash
recipient.requestType = BigInt.fromI32(event.params._type).toString()
recipient.submissionTime = event.params._timestamp.toString()
recipient.verified = false
recipient.save()
} else {
// deleteRecipient request
// no need to update metadata and recipient address as they are not available for delete requests
let recipient = Recipient.load(recipientId)
if (recipient == null) {
// this should not happen, record the transaction hash for troubleshooting
recipient = new Recipient(recipientId)
recipient.requestSubmittedHash = event.transaction.hash
}
recipient.recipientRegistry = recipientRegistryId
recipient.requestType = BigInt.fromI32(event.params._type).toString()
recipient.submissionTime = event.params._timestamp.toString()
recipient.verified = false
recipient.save()
}
}
19 changes: 16 additions & 3 deletions vue-app/src/api/recipient-registry-optimistic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export enum RequestStatus {
Accepted = 'Accepted',
Rejected = 'Rejected',
Executed = 'Live',
PendingRemoval = 'Pending removal',
Removed = 'Removed',
}

Expand Down Expand Up @@ -131,6 +132,10 @@ export async function getRequests(registryInfo: RegistryInfo, registryAddress: s

if (recipient.verified) {
request.status = requestType === RequestTypeCode.Removal ? RequestStatus.Removed : RequestStatus.Executed
} else {
if (requestType === RequestTypeCode.Removal) {
request.status = RequestStatus.PendingRemoval
}
}

// In case there are two requests submissions events, we always prioritize
Expand Down Expand Up @@ -255,6 +260,9 @@ export async function getProjects(registryAddress: string, startTime?: number, e
// Disallow contributions to removed recipient, but don't hide it
project.isLocked = true
}
} else {
// project is not removed yet, keep the index so that it can still receive contributions
project.index = recipient.recipientIndex
}
}

Expand Down Expand Up @@ -309,9 +317,14 @@ export async function getProject(recipientId: string, filter = true): Promise<Pr
}
}

if (requestType === RequestTypeCode.Removal && recipient.verified) {
// Disallow contributions to removed recipient
project.isLocked = true
if (requestType === RequestTypeCode.Removal) {
if (recipient.verified) {
// Disallow contributions to removed recipient
project.isLocked = true
} else {
// project is not removed yet, keep the index so that it can still receive contributions
project.index = recipient.recipientIndex
}
}
return project
}
Expand Down
6 changes: 1 addition & 5 deletions vue-app/src/views/RecipientRegistry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,7 @@
>
<img src="@/assets/checkmark.svg" />
</div>
<div
class="icon-btn-reject"
v-if="isOwner && (isPending(request) || isAccepted(request))"
@click="reject(request)"
>
<div class="icon-btn-reject" v-if="isOwner && isPending(request)" @click="reject(request)">
<img src="@/assets/close.svg" />
</div>
</div>
Expand Down

0 comments on commit 36ae4ac

Please sign in to comment.