Skip to content

Commit

Permalink
Enable withdraws
Browse files Browse the repository at this point in the history
  • Loading branch information
ccali11 committed Oct 25, 2023
1 parent c988e27 commit f8bd5c7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/web/src/composables/operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default function useOperators() {

async function getUserOperators(): Promise<void> {
const userAddresses = user.value?.accounts.map((account: Account) => account.address) as string[]
console.log('ethereumUrl :>> ', ethereumUrl)

const scanner = new Scanner({
ethereumUrl,
ssvNetworkAddress,
Expand Down
12 changes: 9 additions & 3 deletions apps/web/src/composables/staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { ref } from 'vue'
import { ethers } from 'ethers'
import { ProviderString } from '@casimir/types'
import useContracts from '@/composables/contracts'
import useEnvironment from '@/composables/environment'
import useEthers from '@/composables/ethers'
import useLedger from '@/composables/ledger'
import useTrezor from '@/composables/trezor'
import useWalletConnectV2 from './walletConnectV2'
import { CasimirManager } from '@casimir/ethereum/build/@types'

const { getContracts } = useContracts()
const { provider } = useEnvironment()
const { ethersProviderList, getEthersBrowserSigner } = useEthers()
const { getEthersLedgerSigner } = useLedger()
const { getEthersTrezorSigner } = useTrezor()
Expand Down Expand Up @@ -105,9 +107,13 @@ export default function useStaking() {
const managerSigner = (manager as CasimirManager).connect(signer as ethers.Signer)
const value = ethers.utils.parseEther(amount)
// const withdrawableBalance = await (manager as CasimirManager).getWithdrawableBalance()
const withdrawableBalance = await managerSigner.getBufferedBalance()
console.log('withdrawableBalance :>> ', withdrawableBalance)
return await managerSigner.requestWithdrawal(value)
const bufferedBalance = await managerSigner.getBufferedBalance()
const bufferedBalanceNumber = parseFloat(ethers.utils.formatEther(bufferedBalance))
const result = await managerSigner.requestWithdrawal(value)
return {
result,
bufferedBalance: bufferedBalanceNumber
}
}

return {
Expand Down
6 changes: 4 additions & 2 deletions apps/web/src/pages/overview/components/Staking.vue
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,13 @@ const handleWithdraw = async () => {
// return alert(`The account you selected is not the same as the one that is active in your ${selectedStakingProvider.value} wallet. Please open your browser extension and select the account that you want to log in with.`)
// }
const result = await withdraw({
const { result, bufferedBalance } = await withdraw({
amount: formattedAmountToStake.value,
walletProvider: selectedStakingProvider.value,
type: stakeType.value
})
console.log('result :>> ', result)
console.log('bufferedBalance :>> ', bufferedBalance)
if (!result) stakeButtonText.value = 'Failed!'
stakeButtonText.value = 'Withdrawn!'
Expand Down Expand Up @@ -536,7 +538,7 @@ function setStakeOrWithdraw(option: 'stake' | 'withdraw') {
<button
class="submit-button h-[37px] w-full "
:class="success ? 'bg-approve' : failure ? 'bg-decline' : 'bg-primary'"
:disabled="!(termsOfServiceCheckbox && selectedWalletAddress && formattedAmountToStake && !errorMessage) || stakeButtonText !== 'Stake'"
:disabled="!(termsOfServiceCheckbox && selectedWalletAddress && formattedAmountToStake && !errorMessage) || (stakeButtonText !== 'Stake' && stakeButtonText !== 'Withdraw')"
@click="stakeOrWithdraw === 'stake' ? handleDeposit() : handleWithdraw()"
>
<div
Expand Down

0 comments on commit f8bd5c7

Please sign in to comment.