Skip to content

Commit

Permalink
Fix testnet faucet for localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
sisou committed May 19, 2022
1 parent 19d24c5 commit 3a4f6f1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/components/TestnetFaucet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { defineComponent, ref, Ref } from '@vue/composition-api';
import { CircleSpinner, CrossIcon } from '@nimiq/vue-components';
import { LocaleMessage } from 'vue-i18n';
import { MAINNET_ORIGIN } from '../lib/Constants';
import { MAINNET_ORIGIN, TESTNET_ORIGIN } from '../lib/Constants';
type FaucetInfoResponse = {
network: 'test' | 'main',
Expand Down Expand Up @@ -70,7 +70,10 @@ export default defineComponent({
const faucetInfoPromise = fetch(`${FAUCET_URL}/info`)
.then((res) => res.json() as Promise<FaucetInfoResponse>)
.then((faucet) => {
const expectedNetwork = window.location.origin === MAINNET_ORIGIN ? 'main' : 'test';
const expectedNetwork = {
[MAINNET_ORIGIN]: 'main',
[TESTNET_ORIGIN]: 'test',
}[window.location.origin];
if (faucet.network !== expectedNetwork) {
unavailableMsg.value = context.root.$t('Faucet unavailable (wrong network)');
Expand Down
4 changes: 3 additions & 1 deletion src/lib/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export const ENV_TEST = 'test';
export const ENV_DEV = 'dev';

export const MAINNET_ORIGIN = 'https://wallet.nimiq.com';
export const TESTNET_ORIGIN = 'https://wallet.nimiq-testnet.com';
export const TESTNET_ORIGIN = window.location.hostname === 'localhost'
? 'http://localhost:8081'
: 'https://wallet.nimiq-testnet.com';

export const FIAT_CURRENCY_DENYLIST = [
'BDT', 'BHD', 'BMD', 'KWD', 'LKR', 'MMK', 'SAR',
Expand Down

0 comments on commit 3a4f6f1

Please sign in to comment.