Skip to content

Commit

Permalink
fix: fixed params for xDAI Chain
Browse files Browse the repository at this point in the history
  • Loading branch information
hbarcelos committed Jul 23, 2021
1 parent 4fba2ce commit 107d58c
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/api/side-chain/chain-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const supportedSideChains = {
// xDai
100: {
chainId: 100,
chainName: "xDAI",
chainName: "xDAI Chain",
nativeCurrency: { name: "xDAI", symbol: "xDAI", decimals: 18 },
rpcUrls: [ensureEnv("REACT_APP_WEB3_FALLBACK_XDAI_HTTPS_URL")],
blockExplorerUrls: [getBaseUrl(100)],
Expand Down
95 changes: 71 additions & 24 deletions src/components/alternative-chain-court.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,6 @@ export default function AlternativeChainCourt() {

return isSupportedSideChain(destinationChainId) ? (
<DestinationChainIdContext.Provider value={destinationChainId}>
<AlternativeChainBanner
message={
<>
Kleros Court is now{" "}
<StyledResponsiveBannerButton type="link" onClick={switchNetwork}>
available on {chainIdToNetworkName[destinationChainId]}
</StyledResponsiveBannerButton>
.
</>
}
/>
<StyledWrapper>
<AlternativeChainCourtWrapper />
</StyledWrapper>
Expand Down Expand Up @@ -110,13 +99,56 @@ function SideChainCourtDecisionTree() {
const switchNetwork = useSwitchNetwork(destinationChainId);

return hasErrors || hasAnyBalance ? (
<AlternativeChainCourtLink
ButtonComponent={StyledButtonLink}
destinationChainId={destinationChainId}
onClick={switchNetwork}
/>
<>
<AlternativeChainCourtLink
ButtonComponent={StyledButtonLink}
destinationChainId={destinationChainId}
onClick={switchNetwork}
/>
<AlternativeChainBanner
message={
<>
Kleros Court is now available on{" "}
{
<AlternativeChainCourtLink
ButtonComponent={StyledResponsiveBannerButton}
icon={null}
destinationChainId={destinationChainId}
text={chainIdToNetworkName[destinationChainId]}
/>
}
.
</>
}
/>
</>
) : (
<SideChainCourtModal balance={balance} rawBalance={rawBalance} errors={errors} />
<>
<SideChainCourtModal balance={balance} rawBalance={rawBalance} errors={errors} />
<AlternativeChainBanner
message={
<>
Kleros Court is now available on{" "}
{
<SideChainCourtModal
balance={balance}
rawBalance={rawBalance}
errors={errors}
trigger={
<AlternativeChainCourtLink
ButtonComponent={StyledResponsiveBannerButton}
icon={null}
destinationChainId={destinationChainId}
text={chainIdToNetworkName[destinationChainId]}
/>
}
/>
}
.
</>
}
/>
</>
);
}

Expand Down Expand Up @@ -244,7 +276,7 @@ const StyledWrapper = styled.div`
}
`;

function SideChainCourtModal({ balance, rawBalance, errors }) {
function SideChainCourtModal({ balance, rawBalance, errors, trigger }) {
const [visible, setVisible] = React.useState(false);
const destinationChainId = useDestinationChainId();

Expand All @@ -253,6 +285,17 @@ function SideChainCourtModal({ balance, rawBalance, errors }) {
const [autoSwitchEnabled, setAutoSwitchEnabled] = React.useState(false);
const hasAnyBalance = [balance, rawBalance].some((value) => (value ? toBN(value).gt(toBN("0")) : false));

const triggerElement = React.cloneElement(trigger, {
destinationChainId,
onClick: (e) => {
if (typeof trigger.props?.onClick === "function") {
trigger.props.onClick(e);
}

setVisible(true);
},
});

React.useEffect(() => {
if (autoSwitchEnabled && hasAnyBalance) {
switchNetwork();
Expand All @@ -261,11 +304,7 @@ function SideChainCourtModal({ balance, rawBalance, errors }) {

return (
<>
<AlternativeChainCourtLink
ButtonComponent={StyledButtonLink}
destinationChainId={destinationChainId}
onClick={() => setVisible(true)}
/>
{triggerElement}
<StyledModal
centered
closable
Expand Down Expand Up @@ -319,12 +358,17 @@ function SideChainCourtModal({ balance, rawBalance, errors }) {
SideChainCourtModal.propTypes = {
balance: t.oneOfType([t.string, t.any.isRequired]),
rawBalance: t.oneOfType([t.string, t.any.isRequired]),
trigger: t.element,
errors: t.shape({
balance: t.instanceOf(Error),
rawBalance: t.instanceOf(Error),
}),
};

SideChainCourtModal.defaultProps = {
trigger: <AlternativeChainCourtLink ButtonComponent={StyledButtonLink} />,
};

const StyledModal = styled(Modal)`
.ant-modal-header {
border: none;
Expand Down Expand Up @@ -383,7 +427,10 @@ const StyledButtonLink = styled(ButtonLink)`
}
`;

const StyledResponsiveBannerButton = styled(Button)`
const StyledResponsiveBannerButton = styled(Button).attrs((props) => ({
...props,
type: props.type ?? "link",
}))`
color: inherit;
line-height: inherit;
height: auto;
Expand Down

0 comments on commit 107d58c

Please sign in to comment.