-
-
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: chain select on v4 project page -> reserved token card
- Loading branch information
1 parent
77a1af2
commit 5afe8d8
Showing
35 changed files
with
418 additions
and
173 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
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 |
---|---|---|
@@ -1,20 +1,14 @@ | ||
import { JBChainId } from "juice-sdk-core"; | ||
import { useSuckers } from "juice-sdk-react"; | ||
import { useCurrentRouteChainId } from "./useCurrentRouteChainId"; | ||
|
||
// Gets the projectId of a project on a particular chain | ||
// Gets the projectId of a project on a given chain | ||
// -> (Project IDs can vary across chains) | ||
// | ||
// If project does not exist on given chain, returns undefined | ||
export function useProjectIdOfChain({ | ||
chainId | ||
}: { | ||
chainId: JBChainId | undefined | ||
}) { | ||
const currentRouteChainId = useCurrentRouteChainId() | ||
const _chainId = chainId ?? currentRouteChainId | ||
|
||
}) { | ||
const { data: suckers } = useSuckers() | ||
|
||
return suckers?.find((suckerPair) => suckerPair.peerChainId === _chainId )?.peerChainId | ||
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 | ||
// } | ||
} |
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
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,40 @@ | ||
import { JBChainId, JBRulesetData, JBRulesetMetadata } from "juice-sdk-core"; | ||
|
||
export function getDiffedAttrBetweenRulesets(rulesetsByChain: Record<JBChainId, { | ||
ruleset: JBRulesetData, | ||
metadata: JBRulesetMetadata | ||
}>) { | ||
// Get a list of all attributes we're keeping (diffed attributes) | ||
const diffedRulesetAttrs = Object.keys(Object.values(rulesetsByChain)[0].ruleset).filter((rulesetAttr) => ( | ||
// @ts-ignore | ||
rulesets.slice(1).some(({ ruleset }) => Boolean(ruleset[rulesetAttr] !== rulesets[0][rulesetAttr])) | ||
)) | ||
|
||
const diffedMetadataAttrs = Object.keys(Object.values(rulesetsByChain)[0].metadata).filter((metadataAttr) => ( | ||
// @ts-ignore | ||
rulesets.slice(1).some(({ ruleset }) => Boolean(ruleset[metadataAttr] !== rulesets[0][metadataAttr])) | ||
)) | ||
|
||
if (!diffedRulesetAttrs.length && !diffedMetadataAttrs) return [] | ||
|
||
const rulesetsWithDiffedAttrsOnly = {} as Record<JBChainId, Partial<JBRulesetData & JBRulesetMetadata>> | ||
|
||
Object.keys(rulesetsByChain).map((chainIdStr) => { | ||
const chainId = parseInt(chainIdStr) as JBChainId | ||
const ruleset = rulesetsByChain[chainId].ruleset | ||
const metadata = rulesetsByChain[chainId].metadata | ||
rulesetsWithDiffedAttrsOnly[chainId] = {} | ||
|
||
diffedRulesetAttrs.forEach((rulesetAttr) => { | ||
// @ts-ignore | ||
rulesetsWithDiffedAttrsOnly[chainId][rulesetAttr] = ruleset[rulesetAttr] | ||
}) | ||
|
||
diffedMetadataAttrs.forEach((metadataAttr) => { | ||
// @ts-ignore | ||
rulesetsWithDiffedAttrsOnly[chainId][metadataAttr] = metadata[rulesetAttr] | ||
}) | ||
}) | ||
|
||
return rulesetsWithDiffedAttrsOnly | ||
} |
Oops, something went wrong.