diff --git a/app/[id]/page.tsx b/app/[...slug]/page.tsx similarity index 73% rename from app/[id]/page.tsx rename to app/[...slug]/page.tsx index 00e8b3c..034ec63 100644 --- a/app/[id]/page.tsx +++ b/app/[...slug]/page.tsx @@ -5,12 +5,12 @@ import ParticlesComponent from "@/components/ParticlesComponent"; export default function FaucetPage({ params, }: { - params: { id: string }; + params: { slug: [string, string] }; }) { return (
- +
); }; \ No newline at end of file diff --git a/components/Faucet.tsx b/components/Faucet.tsx index b05a78a..aeeabd4 100644 --- a/components/Faucet.tsx +++ b/components/Faucet.tsx @@ -13,12 +13,14 @@ import { Disburse } from "@/app/page"; function FaucetForm( { url, + address, buttonText, setButtonText, setIsSubmitting, isSubmitting }: { url: string; + address: string; buttonText: string; setButtonText: (text: string) => void; setIsSubmitting: (submitting: boolean) => void; @@ -290,8 +292,8 @@ function FaucetForm( onKeyDown={checkAmount} inputMode="decimal" onChange={(e) => setUser({ ...user, amount: e.target.value.replace(",", ".") })} /> - @@ -327,7 +329,7 @@ function FaucetForm( ); }; -export default function Faucet({ url }: { url: string }) { +export default function Faucet({ url, address }: { url: string, address: string }) { const [isLoading, setLoading] = useState(true); const [buttonText, setButtonText] = useState("Request Tokens"); const [isSubmitting, setIsSubmitting] = useState(false); @@ -342,7 +344,7 @@ export default function Faucet({ url }: { url: string }) { {isLoading ? ( ) : ( - + )} ); diff --git a/context/index.tsx b/context/index.tsx index 114cf34..9ac2f7f 100644 --- a/context/index.tsx +++ b/context/index.tsx @@ -94,10 +94,11 @@ export const FaucetProvider = ({ children }: { children: React.ReactNode }) => { const [switcherMode, setSwitcherMode] = useState(); const [selectorMode, setSelectorMode] = useState([]); const path = usePathname().split("/")[1]; + const address = usePathname().split("/")[2]; const [user, setUser] = useState({ chain: "", - address: "", + address: address || "", amount: "", }); const [toggle, setToggle] = useState(true); @@ -147,16 +148,25 @@ export const FaucetProvider = ({ children }: { children: React.ReactNode }) => { symbol: chain.nativeCurrency.symbol, }; })); - // console.log("polkadot accounts", balances); + console.log("polkadot accounts", balances); setPolkadotAccounts(balances); - setSelectedPolkadotAccount(encodeAddress(decodeAddress(sessionStorage.getItem("selectedAccount") || balances[0].address), chain.prefix)); - setUser((previous) => ({ ...previous, address: encodeAddress(decodeAddress(sessionStorage.getItem("selectedAccount") || balances[0].address), chain.prefix), chain: sessionStorage.getItem("selectedChain") || balances[0].chain })); + if(address) { + balances.forEach(balance => { + if (balance.address === address) { + setSelectedPolkadotAccount(encodeAddress(decodeAddress(balance.address), chain.prefix)); + setUser((previous) => ({ ...previous, address: encodeAddress(decodeAddress(balance.address), chain.prefix), chain: balance.chain })); + } + }); + } else { + setSelectedPolkadotAccount(encodeAddress(decodeAddress(sessionStorage.getItem("selectedAccount") || balances[0].address), chain.prefix)); + setUser((previous) => ({ ...previous, address: encodeAddress(decodeAddress(sessionStorage.getItem("selectedAccount") || balances[0].address), chain.prefix), chain: sessionStorage.getItem("selectedChain") || balances[0].chain })); + } return true; }; } catch (err) { console.log(err); } - }, [setSelectedPolkadotAccount]); + }, [setSelectedPolkadotAccount, address]); const updateEthereumBalances = useCallback(async (chain: Chain) => { console.log(`Updating ${chain.name} balances...`); @@ -388,7 +398,6 @@ export const FaucetProvider = ({ children }: { children: React.ReactNode }) => { async function connectSubstrateOnReload() { const isSubstrateConnected = sessionStorage.getItem("isSubstrateConnected"); const chain = chains.find((chain) => chain.name === sessionStorage.getItem("selectedChain"))!; - console.log(chain); if (isSubstrateConnected === "true") { const res = await updatePolkadotBalances(chain); if (res) { diff --git a/yarn.lock b/yarn.lock index 72d4968..68c66dc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2419,9 +2419,9 @@ eastasianwidth@^0.2.0: integrity sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA== electron-to-chromium@^1.5.4: - version "1.5.7" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.7.tgz#425d2a7f76ecfa564fdca1040d11fb1979851f3c" - integrity sha512-6FTNWIWMxMy/ZY6799nBlPtF1DFDQ6VQJ7yyDP27SJNt5lwtQ5ufqVvHylb3fdQefvRcgA3fKcFMJi9OLwBRNw== + version "1.5.8" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.8.tgz#0a3225b305212f347be48f159a3c0a117d5e9801" + integrity sha512-4Nx0gP2tPNBLTrFxBMHpkQbtn2hidPVr/+/FTtcCiBYTucqc70zRyVZiOLj17Ui3wTO7SQ1/N+hkHYzJjBzt6A== elliptic@^6.5.4: version "6.5.7"