refresh redeem page correctly

This commit is contained in:
Maximilian Schneider 2021-08-11 21:20:39 +02:00
parent a959a7c06c
commit ec04c38fc7
2 changed files with 40 additions and 3 deletions

View File

@ -109,8 +109,10 @@ export default function useWallet() {
// refresh usdc vault regularly
useInterval(async () => {
actions.fetchUsdcVault()
}, 20 * SECONDS)
await actions.fetchUsdcVault()
await actions.fetchMNGOVault()
await actions.fetchRedeemableMint()
}, 10 * SECONDS)
return { connected, wallet }
}

View File

@ -186,7 +186,7 @@ const useWalletStore = create<WalletStore>((set, get) => ({
connection,
pool.poolUsdc
)
console.log('fetchUsdcVault', vault)
// console.log('fetchUsdcVault', vault)
set((state) => {
state.usdcVault = vault
@ -212,6 +212,41 @@ const useWalletStore = create<WalletStore>((set, get) => ({
}
})
},
async fetchMNGOVault() {
const connection = get().connection.current
const pool = get().pool
const set = get().set
if (!pool) return
const { account: vault } = await getTokenAccount(
connection,
pool.poolWatermelon
)
// console.log('fetchMNGOVault', vault)
set((state) => {
state.mangoVault = vault
})
},
async fetchRedeemableMint() {
const connection = get().connection.current
const pool = get().pool
const set = get().set
const mintKeys = [pool.redeemableMint]
const mints = await Promise.all(
mintKeys.map((pk) => getMint(connection, pk))
)
// console.log('fetchMints', mints)
set((state) => {
for (const pa of mints) {
state.mints[pa.publicKey.toBase58()] = pa.account
// console.log('mint', pa.publicKey.toBase58(), pa.account)
}
})
},
async submitContribution(amount: number) {
console.log('submitContribution', amount)