Skip to content

Commit

Permalink
faucetBalRequirement update (#1074)
Browse files Browse the repository at this point in the history
* faucetBalRequirement update

* Fetch faucetBalRequirement from faucet API
  • Loading branch information
bobo-k2 authored Dec 5, 2023
1 parent dc6aae0 commit ecbc9d1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/components/assets/EvmNativeToken.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ import { $web3 } from 'src/boot/api';
import { cbridgeAppLink } from 'src/c-bridge';
import ModalFaucet from 'src/components/assets/modals/ModalFaucet.vue';
import TokenBalance from 'src/components/common/TokenBalance.vue';
import { faucetBalRequirement } from 'src/config/wallets';
import { useAccount, useNetworkInfo, usePrice, useBreakpoints } from 'src/hooks';
import { useAccount, useNetworkInfo, usePrice, useBreakpoints, useFaucet } from 'src/hooks';
import { getTokenImage } from 'src/modules/token';
import { buildTransferPageLink, buildEthereumBridgePageLink } from 'src/router/routes';
import { useStore } from 'src/store';
Expand All @@ -112,6 +111,7 @@ export default defineComponent({
const store = useStore();
const isH160 = computed<boolean>(() => store.getters['general/isH160Formatted']);
const isLoading = computed<boolean>(() => store.getters['general/isLoading']);
const { faucetBalRequirement } = useFaucet();
const nativeTokenImg = computed<string>(() =>
getTokenImage({
Expand All @@ -130,7 +130,7 @@ export default defineComponent({
isRocstar.value = nativeTokenSymbol.value === 'RSTR';
isFaucet.value = isRocstar.value
? false
: isShibuya.value || faucetBalRequirement > bal.value;
: isShibuya.value || faucetBalRequirement.value > bal.value;
if (nativeTokenUsd) {
balUsd.value = nativeTokenUsd * bal.value;
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/assets/NativeAssetList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ import {
useNetworkInfo,
usePrice,
useBreakpoints,
useFaucet,
} from 'src/hooks';
import { checkIsNullOrUndefined, truncate } from '@astar-network/astar-sdk-core';
import { getTokenImage } from 'src/modules/token';
Expand All @@ -269,7 +270,6 @@ import ModalEvmWithdraw from 'src/components/assets/modals/ModalEvmWithdraw.vue'
import ModalFaucet from 'src/components/assets/modals/ModalFaucet.vue';
import ModalVesting from 'src/components/assets/modals/ModalVesting.vue';
import { Path } from 'src/router';
import { faucetBalRequirement } from 'src/config/wallets';
export default defineComponent({
components: {
Expand Down Expand Up @@ -301,7 +301,7 @@ export default defineComponent({
const { numEvmDeposit } = useEvmDeposit();
const { nativeTokenUsd } = usePrice();
const { currentNetworkName, nativeTokenSymbol, isSupportAuTransfer } = useNetworkInfo();
const { faucetBalRequirement } = useFaucet();
const xcmNativeToken = computed(() => generateAstarNativeTokenObject(nativeTokenSymbol.value));
const nativeTokenImg = computed(() =>
Expand Down Expand Up @@ -337,7 +337,7 @@ export default defineComponent({
isRocstar.value = tokenSymbolRef === 'RSTR';
isFaucet.value = isRocstar.value
? false
: isShibuya.value || faucetBalRequirement > bal.value;
: isShibuya.value || faucetBalRequirement.value > bal.value;
if (nativeTokenUsd.value) {
balUsd.value = nativeTokenUsd.value * bal.value;
} else {
Expand Down
4 changes: 0 additions & 4 deletions src/config/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,3 @@ export const supportAllWalletsObj = {
export const supportEvmWallets = objToArray(supportEvmWalletObj) as Wallet[];
export const supportWallets = objToArray(supportWalletObj) as Wallet[];
export const supportAllWallets = objToArray(supportAllWalletsObj) as Wallet[];

// Memo: defined by hard-coding to avoid sending too many requests to faucet API server
// Ref: https://github.com/AstarNetwork/astar-faucet-bot/blob/main/src/clients/astar.ts#L225
export const faucetBalRequirement = 0.01 / 2;
8 changes: 5 additions & 3 deletions src/hooks/useFaucet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import axios from 'axios';
import { DateTime } from 'luxon';
import { providerEndpoints } from 'src/config/chainEndpoints';
import { useStore } from 'src/store';
import { onUnmounted, ref, Ref, watch, watchEffect } from 'vue';
import { onUnmounted, ref, Ref, watch, watchEffect, computed } from 'vue';
import { useAccount, useNetworkInfo } from 'src/hooks';
import { ethers } from 'ethers';
import { fetchNativeBalance } from '@astar-network/astar-sdk-core';
Expand Down Expand Up @@ -31,6 +31,7 @@ interface Countdown {
export function useFaucet(isModalFaucet?: Ref<boolean>) {
const timestamps = ref<Timestamps | null>(null);
const faucetAmount = ref<number>(0);
const faucetBalRequirement = computed<number>(() => faucetAmount.value / 2);
const unit = ref<string>('');
const isAbleToFaucet = ref<boolean>(false);
const hash = ref<string>('');
Expand Down Expand Up @@ -146,7 +147,7 @@ export function useFaucet(isModalFaucet?: Ref<boolean>) {
async () => {
const senderSs58AccountRef = senderSs58Account.value;
const isModalFaucetRef = isModalFaucet && isModalFaucet.value;
if (!senderSs58AccountRef || !isModalFaucetRef) return;
if (!senderSs58AccountRef || faucetAmount.value > 0) return;
const endpoint = providerEndpoints[currentNetworkIdx.value].faucetEndpoint;

const data = await getFaucetInfo({ account: senderSs58AccountRef, endpoint });
Expand All @@ -161,7 +162,7 @@ export function useFaucet(isModalFaucet?: Ref<boolean>) {
timestamps.value = data.timestamps;
faucetHotWalletBalance.value = ethers.utils.formatEther(hotWalletBal);
},
{ immediate: true }
{ immediate: false }
);

return {
Expand All @@ -172,5 +173,6 @@ export function useFaucet(isModalFaucet?: Ref<boolean>) {
isAbleToFaucet,
countDown,
faucetHotWalletBalance,
faucetBalRequirement,
};
}

0 comments on commit ecbc9d1

Please sign in to comment.