Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bridge-ui-v2): Show warnings on faucet correctly #14676

Merged
merged 3 commits into from
Sep 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions packages/bridge-ui-v2/src/components/Faucet/Faucet.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

let selectedToken: Token;
let mintButtonEnabled = false;
let reasonNotMintable = '';
let alertMessage = '';

async function switchNetworkToL1() {
if (switchingNetwork) return;
Expand Down Expand Up @@ -113,12 +113,12 @@
// This function will check whether or not the button to mint should be
// enabled. If it shouldn't it'll also set the reason why so we can inform
// the user why they can't mint
async function updateMintButtonState(token?: Token, network?: Chain) {
async function updateMintButtonState(connected: boolean, token?: Token, network?: Chain) {
if (!token || !network) return false;

checkingMintable = true;
mintButtonEnabled = false;
reasonNotMintable = '';
let reasonNotMintable = '';

try {
await checkMintable(token, network.id);
Expand All @@ -143,20 +143,22 @@
} finally {
checkingMintable = false;
}

alertMessage = getAlertMessage(connected, wrongChain, reasonNotMintable);
}

function getAlertMessage(connected: boolean, wrongChain: boolean, reasonNotMintable: string) {
if (!connected) return $t('messages.account.required');
//does this really need to be dynamic? Our mint tokens will most likely stay on Sepolia
if (wrongChain) return $t('faucet.wrong_chain.message', { values: { network: 'Sepolia' } });
if (reasonNotMintable) return reasonNotMintable;
return ''
}

$: connected = isUserConnected($account);
$: wrongChain = isWrongChain($network);
$: alertMessage = getAlertMessage(connected, wrongChain, reasonNotMintable);

$: updateMintButtonState(selectedToken, $network);
$: updateMintButtonState(connected, selectedToken, $network);
</script>

<Card class="w-full md:w-[524px]" title={$t('faucet.title')} text={$t('faucet.description')}>
Expand Down