-
Notifications
You must be signed in to change notification settings - Fork 68
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
💰 Fix update payout proposal creation #4095
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
996fc61
Add the `channelPayoutsComitmentFromPayload` helper function
thesan 4d6081f
Upload the binary payload file instead of the json
thesan 3029200
Do not validate the payload
thesan 582c250
Update tsconfig for better web workers support
thesan 04fd1ac
Geneate the payload hash correctly
thesan 98dcdd5
Fix non web builds
thesan dfb578b
Add a story
thesan 2aba6ad
Fix the `Utils: Crypto` tests
thesan ecee57a
Add more allowed mime types
thesan 8d05f21
Remove mime type constraints
thesan ed3fbc9
Temp validation for min and max cashout
thesan 29c1c0b
Fix failing tests
thesan aa00084
Fix the add new proposal tests
thesan 5a0d28c
Rename the `merkleRootFromBinary` util
thesan 06980b3
Update `@joystream/js`
thesan 4125cff
Patch @joystream/js@1.2.0
thesan c6f1790
Fix the payload validation errors
thesan 2a4eb15
Remove unnecessary changes
thesan 8e759c8
Allow copy from payload size commitment and hash view fields
thesan f19daed
Make the payload non-required
thesan 3262918
Fix the story
thesan 3d33e67
Fix the min/max cashout validation
thesan 6d2ea3e
Make the hardcoded `maxCashoutAllowed` more readable
thesan 5e4fef9
Merge branch 'ephesus' of github.com:Joystream/pioneer into fix/payou…
thesan 56440c2
Address CRs
thesan faf276f
Remove the `payload.uploaderAccount`
thesan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { generateCommitmentFromPayloadFile } from '@joystream/js/content' | ||
import { blake3 } from '@noble/hashes/blake3' | ||
import { encode as encodeHash, toB58String } from 'multihashes' | ||
|
||
// FROM Atlas 5e5f2fed Klaudiusz Dembler (2022-01-11 11:09): Giza: update content extrinsics, enable uploads (#1882) | ||
export const hashFile = async (file: Blob): Promise<string> => { | ||
const fileBuffer = await file.arrayBuffer() | ||
const digest = blake3(new Uint8Array(fileBuffer)) | ||
return toB58String(encodeHash(digest, 'blake3')) | ||
} | ||
|
||
export const merkleRootFromBinary = (file: Blob): Promise<string> => { | ||
// It should be `end + 1` because the second parametter of `Blob.start() is the "the first byte that will *not* be included" | ||
// (ref: https://developer.mozilla.org/en-US/docs/Web/API/Blob/slice#end) | ||
const read = async (start: number, end: number) => new Uint8Array(await file.slice(start, end + 1).arrayBuffer()) | ||
return generateCommitmentFromPayloadFile(read) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { uniqueId } from 'lodash' | ||
import { filter, firstValueFrom, fromEvent, Observable } from 'rxjs' | ||
|
||
import { WorkerRequest, WorkerRequestType, WorkerResponse } from './utils' | ||
|
||
let worker: Worker | ||
let messages: Observable<MessageEvent<WorkerResponse>> | ||
|
||
export const hashFile = computeInWorker('HASH_FILE') | ||
|
||
export const merkleRootFromBinary = computeInWorker('MERKLE_ROOT') | ||
|
||
function computeInWorker(type: WorkerRequestType) { | ||
return async (file: Blob): Promise<string> => { | ||
if (!worker) { | ||
worker = new Worker(new URL('./worker', import.meta.url), { type: 'module' }) | ||
messages = fromEvent<MessageEvent<WorkerResponse>>(worker, 'message') | ||
} | ||
|
||
const request: WorkerRequest = { type, id: uniqueId(), file } | ||
const resultObservable = messages.pipe(filter(({ data }) => data.id === request.id)) | ||
|
||
worker.postMessage(request) | ||
|
||
const { data } = await firstValueFrom(resultObservable) | ||
if (data.error) throw Error(data.value) | ||
return data.value | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './client' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { merkleRootFromBinary, hashFile } from '..' | ||
|
||
export type WorkerRequestType = 'HASH_FILE' | 'MERKLE_ROOT' | ||
export type WorkerRequest = { | ||
type: WorkerRequestType | ||
id: string | ||
file: Blob | ||
} | ||
|
||
export type WorkerResponse = { | ||
type: WorkerRequestType | ||
id: string | ||
value: string | ||
error?: boolean | ||
} | ||
|
||
export const compute = async (type: WorkerRequestType, file: Blob): Promise<string> => { | ||
switch (type) { | ||
case 'HASH_FILE': | ||
return await hashFile(file) | ||
case 'MERKLE_ROOT': | ||
return await merkleRootFromBinary(file) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { compute, WorkerRequest, WorkerResponse } from './utils' | ||
|
||
self.onmessage = async ({ data: { type, id, file } }: MessageEvent<WorkerRequest>) => { | ||
try { | ||
const response: WorkerResponse = { type, id, value: await compute(type, file) } | ||
self.postMessage(response) | ||
} catch (error) { | ||
self.postMessage({ type, id, error: true, value: String(error) }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { VoteForCouncilModalCall } from './types' | ||
export type { VoteForCouncilModalCall } from './types' | ||
export * from './VoteForCouncilModal' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
packages/ui/src/proposals/components/StorybookTemplates.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React, { FC } from 'react' | ||
|
||
import { Modal, ModalHeader } from '@/common/components/Modal' | ||
import { StepperStep } from '@/common/components/Stepper' | ||
import { StepDescriptionColumn, Stepper, StepperBody, StepperModalBody } from '@/common/components/StepperModal' | ||
import { StepperProposalWrapper } from '@/proposals/modals/AddNewProposal' | ||
|
||
const steps: StepperStep[] = [ | ||
{ title: 'Proposal type', type: 'past' }, | ||
{ title: 'General parameters', type: 'past' }, | ||
{ title: 'Staking account', type: 'past', isBaby: true }, | ||
{ title: 'Proposal details', type: 'past', isBaby: true }, | ||
{ title: 'Trigger & Discussion', type: 'past', isBaby: true }, | ||
{ title: 'Specific parameters', type: 'active' }, | ||
] | ||
|
||
export const AddNewProposalTemplate: FC<{ title: string }> = ({ title, children }) => ( | ||
<Modal onClose={() => undefined} modalSize="l" modalHeight="xl"> | ||
<ModalHeader onClick={() => undefined} title={`Creating new proposal: ${title}`} /> | ||
<StepperModalBody> | ||
<StepperProposalWrapper> | ||
<Stepper steps={steps} /> | ||
<StepDescriptionColumn></StepDescriptionColumn> | ||
<StepperBody>{children}</StepperBody> | ||
</StepperProposalWrapper> | ||
</StepperModalBody> | ||
</Modal> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...components/SpecificParameters/ChannelIncentivesPayout/ChannelIncentivesPayout.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Meta, Story } from '@storybook/react' | ||
import React from 'react' | ||
|
||
import { AddNewProposalTemplate } from '@/proposals/components/StorybookTemplates' | ||
|
||
import { ChannelIncentivesPayout } from './ChannelIncentivesPayout' | ||
|
||
export default { | ||
title: 'Proposals/AddNewProposalModal/ChannelIncentivesPayout', | ||
component: ChannelIncentivesPayout, | ||
} as Meta | ||
|
||
const Template: Story = () => ( | ||
<AddNewProposalTemplate title="Channel Update Payout"> | ||
<ChannelIncentivesPayout /> | ||
</AddNewProposalTemplate> | ||
) | ||
|
||
export const Default = Template.bind({}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No way to extract these from API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not yet but it should be available soon: Joystream/joystream#4585