Skip to content

Commit

Permalink
fix: show loading mask if data not loaded yet
Browse files Browse the repository at this point in the history
  • Loading branch information
aramalipoor committed Dec 21, 2022
1 parent 3a34b80 commit 4084661
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/react/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default [
file: packageJson.module,
format: 'esm',
sourcemap: true,
inlineDynamicImports: true,
// inlineDynamicImports: true,
},
plugins: [
peerDepsExternal(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import { useTieredSalesContext } from '../providers/TieredSalesProvider';
type Props = PropsWithChildren<
BareComponentProps & {
tierId?: number;
loadingMask?: React.ReactNode;
}
>;

export const TieredSalesIfNotSoldOut = ({
as,
tierId,
loadingMask = <>...</>,
children,
...attributes
}: Props) => {
Expand All @@ -35,10 +37,7 @@ export const TieredSalesIfNotSoldOut = ({
});

const isSoldOut =
totalMinted?.data &&
!totalMinted.isLoading &&
maxAllocation?.data &&
!maxAllocation.isLoading
maxAllocation?.data && totalMinted?.data
? BigNumber.from(totalMinted?.data).gte(
BigNumber.from(maxAllocation?.data),
)
Expand All @@ -47,5 +46,17 @@ export const TieredSalesIfNotSoldOut = ({
const Component =
as || (attributes.className || attributes.style ? 'span' : Fragment);

return <Component {...attributes}>{!isSoldOut ? children : null}</Component>;
const isLoading = totalMinted.isLoading || maxAllocation.isLoading;

return (
<Component {...attributes}>
{loadingMask &&
isLoading &&
(maxAllocation?.data === undefined || totalMinted?.data === undefined) ? (
<>{loadingMask}</>
) : isSoldOut === false ? (
children
) : null}
</Component>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import { useTieredSalesContext } from '../providers/TieredSalesProvider';
type Props = PropsWithChildren<
BareComponentProps & {
tierId?: number;
loadingMask?: React.ReactNode;
}
>;

export const TieredSalesIfSoldOut = ({
as,
tierId,
loadingMask = <>...</>,
children,
...attributes
}: Props) => {
Expand All @@ -35,10 +37,7 @@ export const TieredSalesIfSoldOut = ({
});

const isSoldOut =
totalMinted?.data &&
!totalMinted.isLoading &&
maxAllocation?.data &&
!maxAllocation.isLoading
maxAllocation?.data && totalMinted?.data
? BigNumber.from(totalMinted?.data).gte(
BigNumber.from(maxAllocation?.data),
)
Expand All @@ -47,5 +46,17 @@ export const TieredSalesIfSoldOut = ({
const Component =
as || (attributes.className || attributes.style ? 'span' : Fragment);

return <Component {...attributes}>{isSoldOut ? children : null}</Component>;
const isLoading = totalMinted.isLoading || maxAllocation.isLoading;

return (
<Component {...attributes}>
{loadingMask &&
isLoading &&
(maxAllocation?.data === undefined || totalMinted?.data === undefined) ? (
<>{loadingMask}</>
) : isSoldOut === true ? (
children
) : null}
</Component>
);
};

0 comments on commit 4084661

Please sign in to comment.