Описание изменений
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
"vue": "^3.4.21"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^5.2.1",
|
||||
"vite": "^5.4.10"
|
||||
"@vitejs/plugin-vue": "^5.0.4",
|
||||
"vite": "^5.1.6"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="amount && currentPrice" class="total-cost">
|
||||
Общая стоимость: {{ formatPrice(currentPrice * amount) }} ETH
|
||||
Общая стоимость: {{ formatPrice(calculateTotalCost()) }} ETH
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -123,6 +123,7 @@ const isOwner = computed(() => {
|
||||
|
||||
// Функции
|
||||
function formatPrice(price) {
|
||||
if (!price) return '0'
|
||||
return formatEther(price)
|
||||
}
|
||||
|
||||
@@ -298,6 +299,12 @@ onMounted(async () => {
|
||||
}
|
||||
})
|
||||
|
||||
// Добавляем функцию для расчета общей стоимости
|
||||
function calculateTotalCost() {
|
||||
if (!currentPrice.value || !amount.value) return BigInt(0)
|
||||
return currentPrice.value * BigInt(amount.value)
|
||||
}
|
||||
|
||||
// Обновляем handlePurchase
|
||||
async function handlePurchase() {
|
||||
if (!amount.value) return
|
||||
@@ -315,9 +322,7 @@ async function handlePurchase() {
|
||||
const signer = await ethersProvider.getSigner()
|
||||
const contract = new Contract(contractAddress, contractABI, signer)
|
||||
|
||||
const price = await contract.price()
|
||||
console.log('Цена для покупки:', formatEther(price), 'ETH')
|
||||
const totalCost = price * BigInt(amount.value)
|
||||
const totalCost = calculateTotalCost()
|
||||
console.log('Общая стоимость:', formatEther(totalCost), 'ETH')
|
||||
|
||||
const tx = await contract.purchase(amount.value, {
|
||||
@@ -330,12 +335,12 @@ async function handlePurchase() {
|
||||
amount.value = ''
|
||||
success.value = 'Покупка успешно совершена!'
|
||||
await fetchPrice()
|
||||
} catch (error) {
|
||||
console.error('Ошибка при покупке:', error)
|
||||
if (error.message.includes('user rejected')) {
|
||||
} catch (err) {
|
||||
console.error('Ошибка при покупке:', err)
|
||||
if (err.message.includes('user rejected')) {
|
||||
error.value = 'Транзакция отменена пользователем'
|
||||
} else {
|
||||
error.value = 'Произошла ошибка при совершении покупки: ' + error.message
|
||||
error.value = 'Произошла ошибка при совершении покупки: ' + err.message
|
||||
}
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
|
||||
@@ -271,7 +271,7 @@
|
||||
dependencies:
|
||||
undici-types "~6.19.2"
|
||||
|
||||
"@vitejs/plugin-vue@^5.2.1":
|
||||
"@vitejs/plugin-vue@^5.0.4":
|
||||
version "5.2.1"
|
||||
resolved "https://registry.yarnpkg.com/@vitejs/plugin-vue/-/plugin-vue-5.2.1.tgz#d1491f678ee3af899f7ae57d9c21dc52a65c7133"
|
||||
integrity sha512-cxh314tzaWwOLqVes2gnnCtvBDcM1UMdn+iFR+UjAn411dPT3tOmqrJjbMd7koZpMAmBM/GqeV4n9ge7JSiJJQ==
|
||||
@@ -492,7 +492,7 @@ undici-types@~6.19.2:
|
||||
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-6.19.8.tgz#35111c9d1437ab83a7cdc0abae2f26d88eda0a02"
|
||||
integrity sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==
|
||||
|
||||
vite@^5.4.10:
|
||||
vite@^5.1.6:
|
||||
version "5.4.14"
|
||||
resolved "https://registry.yarnpkg.com/vite/-/vite-5.4.14.tgz#ff8255edb02134df180dcfca1916c37a6abe8408"
|
||||
integrity sha512-EK5cY7Q1D8JNhSaPKVK4pwBFvaTmZxEnoKXLG/U9gmdDcihQGNzFlgIvaxezFR4glP1LsuiedwMBqCXH3wZccA==
|
||||
|
||||
Reference in New Issue
Block a user