diff --git a/src/blockchain/wallet.js b/src/blockchain/wallet.js index 0b6e02f..b5abd31 100644 --- a/src/blockchain/wallet.js +++ b/src/blockchain/wallet.js @@ -56,6 +56,7 @@ export const useWalletStore = defineStore('wallet', ()=>{ export function onChainChanged(chainId) { console.log('onChainChanged', chainId) chainId = Number(chainId) + socket.emit('chain', chainId) const store = useStore() const ws = useWalletStore() if( chainId !== ws.chainId ) { diff --git a/src/common.js b/src/common.js index 188e6c0..b2f4aca 100644 --- a/src/common.js +++ b/src/common.js @@ -1,3 +1,5 @@ +export const NATIVE_TOKEN = '0x0000000000000000000000000000000000000001' + export function mixin(child, ...parents) { // child is modified directly, assigning fields from parents that are missing in child. parents fields are // assigned by parents order, highest priority first diff --git a/src/components/chart/DCABuilder.vue b/src/components/chart/DCABuilder.vue index cfaab30..f785f51 100644 --- a/src/components/chart/DCABuilder.vue +++ b/src/components/chart/DCABuilder.vue @@ -59,6 +59,7 @@ import Color from "color"; import OrderAmount from "@/components/chart/OrderAmount.vue"; import {MAX_FRACTION, newTranche} from "@/blockchain/orderlib.js"; import {getFeeSchedule} from "@/fees.js"; +import {NATIVE_TOKEN} from "@/common.js"; const s = useStore() const co = useChartOrderStore() @@ -126,7 +127,12 @@ const partsGasHint = computed(()=>{ schedFetcher.invoke(s.vault) return null } - return toPrecision(Number(sched.value.gasFee) * parts.value / 1e18) + ' ETH gas fee' + const ethFee = Number(sched.value.gasFee) * parts.value / 1e18; + const mark = s.markPrice(NATIVE_TOKEN) + if (mark) + return '$' + Number(ethFee*mark).toFixed(2) + ' gas fee' + else + return toPrecision(ethFee) + ' ETH gas fee' }) const intervalIsTotal = ref(false) diff --git a/src/socket.js b/src/socket.js index 85eb043..23352d7 100644 --- a/src/socket.js +++ b/src/socket.js @@ -73,6 +73,11 @@ socket.on('vaults', (chainId, owner, vaults)=>{ } }) +socket.on('mark.usd', (chainId, token, value)=>{ + const s = useStore() + s.markPrices[`${chainId}|${token}`] = Number(value) + // console.log('mark.usd', token, value) +}) function handleOrderStatus(chainId, vault, orderIndex, status) { const s = useStore() diff --git a/src/store/store.js b/src/store/store.js index fb0c99e..6b292f7 100644 --- a/src/store/store.js +++ b/src/store/store.js @@ -107,6 +107,8 @@ export const useStore = defineStore('app', ()=> { const balances = computed( () => vault.value === null ? {} : vaultBalances.value[vault.value] || {} ) const vaultOrders = computed(()=> vault.value === null || (!vault.value in orders.value) ? {} : orders.value[vault.value] ? orders.value[vault.value] : [] ) const tokens = computed(getTokens) + const markPrices = ref({}) // key: `${chainId}|${tokenAddr}` value: USD value + function markPrice(token) { return markPrices.value[`${chainId.value}|${token}`] } const factory = computed(() => !chain.value ? null : chain.value.factory) const helper = computed(() => {console.log('chain helper', chain.value); return !chain.value ? null : chain.value.helper}) const mockenv = computed(() => !chain.value ? null : chain.value.mockenv) @@ -147,6 +149,7 @@ export const useStore = defineStore('app', ()=> { removeTransactionSender, error, closeError, addToken, clock, balances, approved, regionApproved, walletApproved, getBalance, creatingVault, + markPrices, markPrice, } })