-
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: omnichain available payout amount, chain selector on Ruleset/To…
…ken tabs (#4589)
- Loading branch information
1 parent
9794d0f
commit 0b0080e
Showing
44 changed files
with
715 additions
and
257 deletions.
There are no files selected for viewing
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
31 changes: 0 additions & 31 deletions
31
src/packages/v4/components/Create/components/pages/ProjectDetails/ProjectChainSelect.tsx
This file was deleted.
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
42 changes: 42 additions & 0 deletions
42
src/packages/v4/components/ProjectDashboard/ProjectChainSelect.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,42 @@ | ||
import { DEFAULT_PROJECT_CHAIN_ID, NETWORKS } from 'constants/networks' | ||
import { JBChainId, useSuckers } from 'juice-sdk-react' | ||
|
||
import { JuiceListbox } from 'components/inputs/JuiceListbox' | ||
|
||
type ChainSelectOption = { | ||
label: string, | ||
value: JBChainId, | ||
} | ||
|
||
export const ProjectChainSelect: React.FC< | ||
React.PropsWithChildren<{ | ||
value?: JBChainId | ||
onChange?: (value: JBChainId) => void | ||
options?: ChainSelectOption[] | ||
}> | ||
> = ({ value, onChange, options }) => { | ||
const { data: suckers } = useSuckers() | ||
const projectAvailableChains = suckers?.map((suckerPair) => ({ | ||
label: NETWORKS[suckerPair.peerChainId].label, | ||
value: suckerPair.peerChainId | ||
})) | ||
|
||
const _options = projectAvailableChains ?? options | ||
|
||
if (!_options) return null | ||
|
||
return ( | ||
<JuiceListbox | ||
className="text-sm font-normal" | ||
value={{ | ||
label: NETWORKS[value ?? DEFAULT_PROJECT_CHAIN_ID]?.label, | ||
value, | ||
}} | ||
onChange={({ value }) => { | ||
if (!value) return | ||
onChange?.(value as JBChainId) | ||
}} | ||
options={_options} | ||
/> | ||
) | ||
} |
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,37 @@ | ||
import { CashOutTaxRate, ReservedPercent, RulesetWeight, WeightCutPercent } from "juice-sdk-core" | ||
|
||
import { useReadJbControllerAllRulesetsOf } from "juice-sdk-react" | ||
|
||
export function useJBAllRulesetsCrossChain({ | ||
projectId, | ||
rulesetNumber | ||
}: { | ||
projectId: bigint | ||
rulesetNumber: bigint | ||
}) { | ||
const { data, isLoading } = useReadJbControllerAllRulesetsOf({ | ||
args: [ | ||
projectId, | ||
rulesetNumber, | ||
10n, // size (The maximum number of rulesets to return). Arbritrarily set | ||
] | ||
}) | ||
|
||
if (!data) return { data: undefined, isLoading } | ||
|
||
return { | ||
data: data.map((obj) => ({ | ||
ruleset: { | ||
...obj.ruleset, | ||
weight: new RulesetWeight(obj.ruleset.weight), | ||
weightCutPercent: new WeightCutPercent(obj.ruleset.weightCutPercent), | ||
}, | ||
metadata: { | ||
...obj.metadata, | ||
cashOutTaxRate: new CashOutTaxRate(obj.metadata.cashOutTaxRate), | ||
reservedPercent: new ReservedPercent(obj.metadata.reservedPercent) | ||
} | ||
})), | ||
isLoading | ||
} | ||
} |
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,46 @@ | ||
import { CashOutTaxRate, JBChainId, JBRulesetData, JBRulesetMetadata, ReservedPercent, RulesetWeight, WeightCutPercent } from "juice-sdk-core"; | ||
import { useJBContractContext, useReadJbControllerCurrentRulesetOf } from "juice-sdk-react"; | ||
|
||
import { useProjectIdOfChain } from "./useProjectIdOfChain"; | ||
|
||
export function useJBRulesetByChain(chainId: JBChainId | undefined) { | ||
const { contracts } = useJBContractContext(); | ||
const projectId = useProjectIdOfChain({ chainId }) | ||
const { data, isLoading } = useReadJbControllerCurrentRulesetOf({ | ||
chainId, | ||
address: contracts?.controller?.data ?? undefined, | ||
args: [BigInt(projectId ?? 0)], | ||
query: { | ||
select([ruleset, rulesetMetadata]) { | ||
return [ | ||
{ | ||
...ruleset, | ||
weight: new RulesetWeight(ruleset.weight), | ||
weightCutPercent: new WeightCutPercent(ruleset.weightCutPercent), | ||
}, | ||
{ | ||
...rulesetMetadata, | ||
cashOutTaxRate: new CashOutTaxRate(rulesetMetadata.cashOutTaxRate), | ||
reservedPercent: new ReservedPercent( | ||
rulesetMetadata.reservedPercent | ||
), | ||
}, | ||
]; | ||
}, | ||
}, | ||
}); | ||
|
||
if (!chainId) { | ||
return { | ||
ruleset: undefined, | ||
rulesetMetadata: undefined, | ||
isLoading: false, | ||
} | ||
} | ||
|
||
return { | ||
ruleset: data?.[0] as JBRulesetData, | ||
rulesetMetadata: data?.[1] as JBRulesetMetadata, | ||
isLoading, | ||
} | ||
} |
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,14 @@ | ||
import { JBChainId } from "juice-sdk-core"; | ||
import { useSuckers } from "juice-sdk-react"; | ||
|
||
// Gets the projectId of a project on a given chain | ||
// -> (Project IDs can vary across chains) | ||
export function useProjectIdOfChain({ | ||
chainId | ||
}: { | ||
chainId: JBChainId | undefined | ||
}) { | ||
const { data: suckers } = useSuckers() | ||
|
||
return suckers?.find((suckerPair) => suckerPair.peerChainId === chainId )?.projectId | ||
} |
40 changes: 40 additions & 0 deletions
40
src/packages/v4/hooks/useProjectRulesetsDiffAcrossChains.ts
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,40 @@ | ||
import { JBChainId, JBRulesetData, JBRulesetMetadata } from "juice-sdk-core"; | ||
import { useJBContractContext, useSuckers } from "juice-sdk-react"; | ||
|
||
|
||
export function useProjectRulesetsDiffAcrossChains(type: 'upcoming' | 'current') { | ||
const { data: suckers } = useSuckers() | ||
const { projectId, contracts } = useJBContractContext() | ||
|
||
const currentRulesetsAndMetadataByChain = { | ||
// 1234: { | ||
// ruleset: JBRulesetData | ||
// metadata: JBRulesetMetadata | ||
// }, | ||
// etc. | ||
} as Record<JBChainId, JBRulesetData & JBRulesetMetadata> | ||
const upcomingRulesetsAndMetadataByChain = { | ||
// 1234: { | ||
// ruleset: JBRulesetData | ||
// metadata: JBRulesetMetadata | ||
// }, | ||
// etc. | ||
} | ||
// suckers?.forEach((suckerPair) => { | ||
// const { data: currentRuleset, isLoading: currentLoading } = useJBRuleset(suckerPair.chainId) | ||
// const { data: upcomingRuleset, isLoading: upcomingLoading } = useJBUpcomingRuleset(suckerPair.peerChainId as JBChainId) | ||
// // how to fill currentRulesetsAndMetadataByChain and upcomingRulesetsAndMetadataByChain? | ||
// }) | ||
|
||
// if (type === 'upcoming') { | ||
// return { | ||
// data: getDiffedAttrBetweenRulesets(upcomingRulesetsAndMetadataByChain), | ||
// isLoading | ||
// } | ||
// } | ||
|
||
// return { | ||
// data: getDiffedAttrBetweenRulesets(currentRulesetsAndMetadataByChain), | ||
// isLoading | ||
// } | ||
} |
Oops, something went wrong.