Run prettier through everything.
This commit is contained in:
@@ -1,25 +1,24 @@
|
||||
|
||||
import toast from "react-hot-toast";
|
||||
import state, { FaucetAccountRes } from '../index';
|
||||
import toast from 'react-hot-toast'
|
||||
import state, { FaucetAccountRes } from '../index'
|
||||
|
||||
export const names = [
|
||||
"Alice",
|
||||
"Bob",
|
||||
"Carol",
|
||||
"Carlos",
|
||||
"Charlie",
|
||||
"Dan",
|
||||
"Dave",
|
||||
"David",
|
||||
"Faythe",
|
||||
"Frank",
|
||||
"Grace",
|
||||
"Heidi",
|
||||
"Judy",
|
||||
"Olive",
|
||||
"Peggy",
|
||||
"Walter",
|
||||
];
|
||||
'Alice',
|
||||
'Bob',
|
||||
'Carol',
|
||||
'Carlos',
|
||||
'Charlie',
|
||||
'Dan',
|
||||
'Dave',
|
||||
'David',
|
||||
'Faythe',
|
||||
'Frank',
|
||||
'Grace',
|
||||
'Heidi',
|
||||
'Judy',
|
||||
'Olive',
|
||||
'Peggy',
|
||||
'Walter'
|
||||
]
|
||||
|
||||
/* This function adds faucet account to application global state.
|
||||
* It calls the /api/faucet endpoint which in send a HTTP POST to
|
||||
@@ -30,22 +29,22 @@ export const names = [
|
||||
export const addFaucetAccount = async (name?: string, showToast: boolean = false) => {
|
||||
if (typeof window === undefined) return
|
||||
|
||||
const toastId = showToast ? toast.loading("Creating account") : "";
|
||||
const toastId = showToast ? toast.loading('Creating account') : ''
|
||||
const res = await fetch(`${window.location.origin}/api/faucet`, {
|
||||
method: "POST",
|
||||
});
|
||||
const json: FaucetAccountRes | { error: string } = await res.json();
|
||||
if ("error" in json) {
|
||||
method: 'POST'
|
||||
})
|
||||
const json: FaucetAccountRes | { error: string } = await res.json()
|
||||
if ('error' in json) {
|
||||
if (showToast) {
|
||||
return toast.error(json.error, { id: toastId });
|
||||
return toast.error(json.error, { id: toastId })
|
||||
} else {
|
||||
return;
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if (showToast) {
|
||||
toast.success("New account created", { id: toastId });
|
||||
toast.success('New account created', { id: toastId })
|
||||
}
|
||||
const currNames = state.accounts.map(acc => acc.name);
|
||||
const currNames = state.accounts.map(acc => acc.name)
|
||||
state.accounts.push({
|
||||
name: name || names.filter(name => !currNames.includes(name))[0],
|
||||
xrp: (json.xrp || 0 * 1000000).toString(),
|
||||
@@ -55,36 +54,35 @@ export const addFaucetAccount = async (name?: string, showToast: boolean = false
|
||||
hooks: [],
|
||||
isLoading: false,
|
||||
version: '2'
|
||||
});
|
||||
})
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// fetch initial faucets
|
||||
(async function fetchFaucets() {
|
||||
;(async function fetchFaucets() {
|
||||
if (typeof window !== 'undefined') {
|
||||
if (state.accounts.length === 0) {
|
||||
await addFaucetAccount();
|
||||
await addFaucetAccount()
|
||||
// setTimeout(() => {
|
||||
// addFaucetAccount();
|
||||
// }, 10000);
|
||||
}
|
||||
}
|
||||
})();
|
||||
})()
|
||||
|
||||
export const addFunds = async (address: string) => {
|
||||
const toastId = toast.loading("Requesting funds");
|
||||
const toastId = toast.loading('Requesting funds')
|
||||
const res = await fetch(`${window.location.origin}/api/faucet?account=${address}`, {
|
||||
method: "POST",
|
||||
});
|
||||
const json: FaucetAccountRes | { error: string } = await res.json();
|
||||
if ("error" in json) {
|
||||
return toast.error(json.error, { id: toastId });
|
||||
method: 'POST'
|
||||
})
|
||||
const json: FaucetAccountRes | { error: string } = await res.json()
|
||||
if ('error' in json) {
|
||||
return toast.error(json.error, { id: toastId })
|
||||
} else {
|
||||
toast.success(`Funds added (${json.xrp} XRP)`, { id: toastId });
|
||||
const currAccount = state.accounts.find(acc => acc.address === address);
|
||||
toast.success(`Funds added (${json.xrp} XRP)`, { id: toastId })
|
||||
const currAccount = state.accounts.find(acc => acc.address === address)
|
||||
if (currAccount) {
|
||||
currAccount.xrp = (Number(currAccount.xrp) + (json.xrp * 1000000)).toString();
|
||||
currAccount.xrp = (Number(currAccount.xrp) + json.xrp * 1000000).toString()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user