native coin handling
This commit is contained in:
60
src/components/NativeWrap.vue
Normal file
60
src/components/NativeWrap.vue
Normal file
@@ -0,0 +1,60 @@
|
||||
<template>
|
||||
<v-dialog :model-value="modelValue" @update:modelValue="$emit('update:modelValue', $event)">
|
||||
<v-card style="max-width: 25em" class="mx-auto">
|
||||
<v-card-title>
|
||||
<v-icon icon="mdi-location-enter" color="grey-darken-1"/> Wrap ETH into WETH
|
||||
</v-card-title>
|
||||
<v-card-item>
|
||||
<v-text-field class="text-end" type="number" variant="outlined" :min="0" :max="balanceFloat"
|
||||
v-model="floatAmount" :step="balanceFloat/10">
|
||||
<template v-slot:prepend-inner>
|
||||
<v-btn variant="text" text="max" @click="floatAmount=balanceFloat"/>
|
||||
</template>
|
||||
<template v-slot:append-inner>
|
||||
<span>ETH</span>
|
||||
</template>
|
||||
</v-text-field>
|
||||
<v-card-actions>
|
||||
<v-btn text="Cancel" @click="$emit('update:modelValue', false)"/>
|
||||
<v-btn text="Wrap" color="red" @click="wrapNative"/>
|
||||
</v-card-actions>
|
||||
</v-card-item>
|
||||
</v-card>
|
||||
</v-dialog>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {useStore} from "@/store/store";
|
||||
import {computed, ref} from "vue";
|
||||
import {vaultContract} from "@/blockchain/contract.js"
|
||||
import {pendTransaction} from "@/blockchain/wallet.js";
|
||||
import {FixedNumber} from "ethers";
|
||||
|
||||
const s = useStore()
|
||||
const props = defineProps(['modelValue', 'vault', 'maxAmount'])
|
||||
const emit = defineEmits(['update:modelValue'])
|
||||
const balanceFloat = computed(() => Number(props.maxAmount)/1e18)
|
||||
const floatAmount = ref(0)
|
||||
|
||||
function wrapNative() {
|
||||
const vaultAddr = props.vault
|
||||
const valueStr = floatAmount.value.toString();
|
||||
const amount = floatAmount.value === balanceFloat.value ? s.nativeBalance : // maximum
|
||||
FixedNumber.fromString(valueStr,{decimals:18, width:256, signed: false}).value;
|
||||
if( amount === 0n )
|
||||
return
|
||||
console.log('pending wrap', valueStr, amount)
|
||||
pendTransaction(async (signer)=>{
|
||||
const vault = await vaultContract(vaultAddr, signer)
|
||||
return await vault.wrap(amount)
|
||||
})
|
||||
floatAmount.value = 0
|
||||
emit('update:modelValue', false)
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
@use "src/styles/vars" as *;
|
||||
|
||||
</style>
|
||||
Reference in New Issue
Block a user