Skip to content

Commit

Permalink
fix(web): set Rollup filter for multiple from addresses from query …
Browse files Browse the repository at this point in the history
…params (#644)

* fix(web): reset Rollup dropdown based on query parameters for multiple addresses

* chore: add changeset
  • Loading branch information
PJColombo authored Nov 25, 2024
1 parent 67c6e2f commit cc62af6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/eighty-clouds-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blobscan/web": patch
---

Fixed an issue where the Rollup filter was not being set correctly from query parameters
33 changes: 17 additions & 16 deletions apps/web/src/components/Filters/RollupFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,28 @@ type RollupFilterProps = {
const chainId = getChainIdByName(env.NEXT_PUBLIC_NETWORK_NAME);
const rollups = chainId ? getChainRollups(chainId) : [];

export const ROLLUP_OPTIONS: Option[] = [
export const ROLLUP_OPTIONS = [
{
value: "null",
selectedLabel: <Badge size="sm">None</Badge>,
label: "None",
},
...rollups.map<Option>(([name, addresses]) => {
return {
value: addresses,
selectedLabel: (
<RollupBadge rollup={name.toLowerCase() as Rollup} size="sm" />
),
label: (
<div className="flex flex-row items-center gap-2">
<RollupIcon rollup={name.toLowerCase() as Rollup} />
<div>{capitalize(name)}</div>
</div>
),
};
}),
];
...rollups.map(
([name, addresses]) =>
({
value: addresses,
selectedLabel: (
<RollupBadge rollup={name.toLowerCase() as Rollup} size="sm" />
),
label: (
<div className="flex flex-row items-center gap-2">
<RollupIcon rollup={name.toLowerCase() as Rollup} />
<div>{capitalize(name)}</div>
</div>
),
} satisfies Option)
),
] satisfies Option[];

export const RollupFilter: FC<RollupFilterProps> = function ({
onChange,
Expand Down
10 changes: 9 additions & 1 deletion apps/web/src/components/Filters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,19 @@ export const Filters: FC = function () {
if (rollup || from) {
const rollupOptions = ROLLUP_OPTIONS.filter((opt) => {
const fromAddresses = from?.split(FROM_ADDRESSES_FORMAT_SEPARATOR);
const rollupOptionAddresses = Array.isArray(opt.value)
? opt.value
: [opt.value];

return (
opt.value === rollup || fromAddresses?.includes(opt.value as string)
opt.value === rollup ||
rollupOptionAddresses.filter((rollupAddress) =>
fromAddresses?.includes(rollupAddress)
).length > 0
);
});

console.log(rollupOptions);
if (rollupOptions) {
newFilters.rollups = rollupOptions;
}
Expand Down

0 comments on commit cc62af6

Please sign in to comment.