Skip to content

Commit

Permalink
Fix/Provider (#22)
Browse files Browse the repository at this point in the history
* mock daily reward

* creased updating interval for wallet-balances

* updated use-contract composable

* fix interval in use-pool composable

* fix provider in use-contract

* updated rpc urls

---------

Co-authored-by: Yehor Podporinov <yehor.podporinov@Yehors-MacBook-Pro.local>
  • Loading branch information
yehor-podporinov and Yehor Podporinov authored Feb 8, 2024
1 parent 0237578 commit d2b60be
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion src/common/WalletBalances.vue
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ onMounted(() => {
} catch (error) {
ErrorHandler.process(error)
}
}, 30000)
}, 5 * 60 * 1000)
})
onBeforeUnmount(() => {
Expand Down
30 changes: 21 additions & 9 deletions src/composables/use-contract.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { type ETHEREUM_RPC_URLS } from '@/enums'
import { ETHEREUM_CHAINS, ETHEREUM_RPC_URLS } from '@/enums'
import { useWeb3ProvidersStore } from '@/store'
import { factories } from '@/types'
import { config } from '@/config'
import { providers } from 'ethers'
import { computed, ref, type ComputedRef, type Ref, unref } from 'vue'
import { computed, type ComputedRef, ref, type Ref, unref } from 'vue'

type ContractFactoryKey = keyof typeof factories
type ContractFactoryClass<K extends ContractFactoryKey = ContractFactoryKey> =
Expand Down Expand Up @@ -36,13 +37,24 @@ export function useContract<K extends ContractFactoryKey = ContractFactoryKey>(

const web3ProvidersStore = useWeb3ProvidersStore()

const provider: I['provider'] = computed(() =>
rpcUrl
? new providers.JsonRpcProvider(rpcUrl)
: new providers.Web3Provider(
web3ProvidersStore.provider.rawProvider as providers.ExternalProvider,
),
)
const provider: I['provider'] = computed(() => {
if (
!rpcUrl ||
(String(web3ProvidersStore.provider.chainId) ===
(config.IS_MAINNET
? ETHEREUM_CHAINS.ethereum
: ETHEREUM_CHAINS.sepolia) &&
rpcUrl ===
(config.IS_MAINNET
? ETHEREUM_RPC_URLS.ethereum
: ETHEREUM_RPC_URLS.sepolia))
)
return new providers.Web3Provider(
web3ProvidersStore.provider.rawProvider as providers.ExternalProvider,
)

return new providers.JsonRpcProvider(rpcUrl)
})

const signer: I['signer'] = computed(() => provider.value.getSigner())

Expand Down
22 changes: 5 additions & 17 deletions src/composables/use-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,8 @@ export const usePool = (poolId: number) => {

const fetchDailyReward = async (): Promise<BigNumber> => {
if (!poolData.value) throw new Error('poolData unavailable')

if (currentTimestamp.value <= poolData.value.payoutStart.toNumber())
return poolData.value.initialReward

const decreaseIntervalTimestamp = poolData.value.decreaseInterval.toNumber()

const startTimestamp =
currentTimestamp.value -
(currentTimestamp.value % decreaseIntervalTimestamp)
const endTimestamp = startTimestamp + decreaseIntervalTimestamp

return erc1967Proxy.value.getPeriodReward(
poolId,
startTimestamp,
endTimestamp,
)
// TODO: calculate daily reward
return poolData.value.initialReward
}

const fetchPoolData = async (): Promise<Erc1967ProxyType.PoolData> => {
Expand Down Expand Up @@ -240,7 +226,9 @@ export const usePool = (poolId: number) => {
_currentUserRewardUpdateIntervalId = setInterval(async () => {
if (
!web3ProvidersStore.isConnected ||
!web3ProvidersStore.provider.selectedAddress
!web3ProvidersStore.provider.selectedAddress ||
!web3ProvidersStore.isValidChain ||
web3ProvidersStore.isAddingToken
)
return

Expand Down
8 changes: 4 additions & 4 deletions src/enums/chains.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ export enum ETHEREUM_CHAINS {
}

export enum ETHEREUM_RPC_URLS {
ethereum = 'https://mainnet.infura.io/v3/6a6dbd61d68f4101b0a40141e89a5936',
sepolia = 'https://sepolia.infura.io/v3/6a6dbd61d68f4101b0a40141e89a5936',
arbitrum = 'https://arbitrum-mainnet.infura.io/v3/6a6dbd61d68f4101b0a40141e89a5936',
arbitrumSepolia = 'https://arbitrum-sepolia.infura.io/v3/6a6dbd61d68f4101b0a40141e89a5936',
ethereum = 'https://eth.llamarpc.com',
sepolia = 'https://ethereum-sepolia.publicnode.com',
arbitrum = 'https://arbitrum-one.publicnode.com',
arbitrumSepolia = 'https://sepolia-rollup.arbitrum.io/rpc',
}

export enum ETHEREUM_EXPLORER_URLS {
Expand Down

0 comments on commit d2b60be

Please sign in to comment.