2021-07-21 22:08:46 +00:00
< template >
2021-08-01 11:22:17 +00:00
< div
class = "flex-shrink-0 bg-white rounded-lg relative flex flex-col flex-1 px-4 pt-4 pb-6 dark:bg-dark-500"
style = "box-shadow: -1px -3px 10px rgba(12, 25, 91, 0.03), 2px 4px 12px rgba(12, 25, 91, 0.05)"
>
2021-08-06 22:44:51 +00:00
< div class = "flex items-center" >
2021-07-21 22:08:46 +00:00
< div class = "flex mr-4 -space-x-3 overflow-hidden" >
< IconCurrency :currency ="tokenKey" class = "w-12 h-12" no -height / >
< / div >
< div
v - if = "type === 'supply' || type === 'no'"
class = "flex flex-col flex-grow"
>
< div class = "mb-1 font-medium leading-none whitespace-no-wrap text-19" >
{ { formatUsd ( supplyUsd ) } }
< / div >
2021-08-06 22:44:51 +00:00
< div class = "flex max-w-full leading-none" >
2021-07-21 22:08:46 +00:00
< span class = "text-grey-pure text-14"
> { { formatDecimal ( supply ) } } { { symbol } } < / s p a n
>
< Info
: text = "`${formatUsd(priceInUsd, 2)}/${symbol}`"
icon = "price"
class = "ml-1"
/ >
< / div >
< / div >
< div v-if ="type === 'borrow'" class="flex flex-col flex-grow" >
< div class = "mb-1 font-medium leading-none whitespace-no-wrap text-19" >
2021-08-06 22:44:51 +00:00
{ { formatUsd ( borrowUsd ) } }
2021-07-21 22:08:46 +00:00
< / div >
< div class = "flex leading-none whitespace-no-wrap" >
< span class = "text-grey-pure text-14"
2021-08-06 22:44:51 +00:00
> { { formatDecimal ( borrow ) } } { { symbol } } < / s p a n
2021-07-21 22:08:46 +00:00
>
< Info
: text = "`${formatUsd(priceInUsd, 2)}/${symbol}`"
icon = "price"
class = "ml-1"
/ >
< / div >
< / div >
2021-08-06 22:44:51 +00:00
< div class = "flex flex-col self-start space-y-1" >
< Badge v-if ="type === 'no'" color="grey" > No Position < / Badge >
< Badge v-if ="type === 'supply'" color="green" > Supplied < / Badge >
< Badge v-if ="type === 'borrow'" color="yellow" > Borrowed < / Badge >
< Badge
v - tooltip = "
'Collateral Factor is the power to borrow against a particular token. Eg:- if collateral factor of ETH is 0.75 that means for every $100 of ETH you can borrow $75 worth of other assets.'
"
color = "blue"
> C . F : { { cf } } < / B a d g e
>
2021-07-21 22:08:46 +00:00
< / div >
< / div >
< hr class = "mt-4" / >
< div class = "flex items-center justify-around mt-4" >
< div class = "flex-col flex-1 text-center" >
2021-08-06 22:44:51 +00:00
< div class = "flex items-center mb-1 justify-evenly" >
2021-07-21 22:08:46 +00:00
< div
class = "font-medium leading-none text-navi-pure-light dark:text-light text-16"
>
{ { formatPercent ( supplyRate ) } }
< / div >
< RewardsRateBadge
2021-08-06 22:44:51 +00:00
v - if = "rewardsSupported"
protocol - name = "Compound"
token - name = "COMP"
currency = "comp"
2021-07-21 22:08:46 +00:00
: rate = "supplyRewardRate"
/ >
< / div >
< div class = "leading-none whitespace-no-wrap text-grey-pure" > Supply < / div >
< / div >
< Divider vertical class = "h-6" / >
< div class = "flex-col flex-1 text-center" >
2021-08-06 22:44:51 +00:00
< div class = "flex items-center mb-1 justify-evenly" >
2021-07-21 22:08:46 +00:00
< div
class = "font-medium leading-none text-navi-pure-light dark:text-light text-16"
>
2021-08-06 22:44:51 +00:00
{ { formatPercent ( borrowRate ) } }
2021-07-21 22:08:46 +00:00
< / div >
< RewardsRateBadge
2021-08-06 22:44:51 +00:00
v - if = "rewardsSupported"
protocol - name = "Compound"
token - name = "COMP"
currency = "comp"
2021-07-21 22:08:46 +00:00
: rate = "borrowRewardRate"
/ >
< / div >
< div class = "leading-none whitespace-no-wrap text-grey-pure" > Borrow < / div >
< / div >
< / div >
< hr class = "mt-4" / >
2021-08-06 22:44:51 +00:00
< div v-if ="type === 'no'" class="flex items-center justify-around mt-6" >
2021-08-01 11:22:17 +00:00
< button
class = "mr-4 h-10 w-full bg-primary-blue-dark shadow text-white rounded-[4px] hover:bg-primary-blue-hover"
2021-07-21 22:08:46 +00:00
@ click = "showSupply"
>
2021-08-01 11:22:17 +00:00
Supply
< / button >
< button
class = "h-10 w-full text-primary-blue-dark shadow border border-primary-blue-dark hover:border-primary-blue-hover rounded-[4px] hover:text-primary-blue-hover"
@ click = "showBorrow"
2021-07-21 22:08:46 +00:00
>
2021-08-01 11:22:17 +00:00
Borrow
< / button >
2021-07-21 22:08:46 +00:00
< / div >
2021-08-06 22:44:51 +00:00
< div v-if ="type === 'supply'" class="flex items-center justify-around mt-6" >
2021-08-01 11:22:17 +00:00
< button
class = "mr-4 h-10 w-full bg-primary-blue-dark shadow text-white rounded-[4px] hover:bg-primary-blue-hover"
2021-07-21 22:08:46 +00:00
@ click = "showSupply"
>
2021-08-01 11:22:17 +00:00
Supply
< / button >
< button
class = "h-10 w-full text-primary-blue-dark shadow border border-primary-blue-dark hover:border-primary-blue-hover rounded-[4px] hover:text-primary-blue-hover"
@ click = "showWithdraw"
2021-07-21 22:08:46 +00:00
>
2021-08-01 11:22:17 +00:00
Withdraw
< / button >
2021-07-21 22:08:46 +00:00
< / div >
2021-08-06 22:44:51 +00:00
< div v-if ="type === 'borrow'" class="flex items-center justify-around mt-6" >
2021-08-01 11:22:17 +00:00
< button
class = "mr-4 h-10 w-full bg-primary-blue-dark shadow text-white rounded-[4px] hover:bg-primary-blue-hover"
2021-07-21 22:08:46 +00:00
@ click = "showBorrow"
>
2021-08-01 11:22:17 +00:00
Borrow
< / button >
< button
class = "h-10 w-full text-primary-blue-dark shadow border border-primary-blue-dark hover:border-primary-blue-hover rounded-[4px] hover:text-primary-blue-hover"
@ click = "showPayback"
2021-07-21 22:08:46 +00:00
>
2021-08-01 11:22:17 +00:00
Payback
< / button >
2021-07-21 22:08:46 +00:00
< / div >
2021-07-24 23:40:30 +00:00
< / div >
2021-07-21 22:08:46 +00:00
< / template >
< script >
2021-08-06 22:44:51 +00:00
import { computed , defineComponent , useContext } from '@nuxtjs/composition-api'
2021-07-21 22:08:46 +00:00
import { useBigNumber } from '~/composables/useBigNumber'
import { useFormatting } from '~/composables/useFormatting'
2021-08-06 22:44:51 +00:00
import { useNotification } from '~/composables/useNotification'
2021-07-21 22:08:46 +00:00
import { useToken } from '~/composables/useToken'
export default defineComponent ( {
props : {
tokenKey : { type : String , required : true } ,
tokenId : { type : String , default : null } ,
supply : { type : String , required : true } ,
supplyUsd : { type : String , required : true } ,
borrow : { type : String , required : true } ,
borrowUsd : { type : String , required : true } ,
supplyRate : { type : String , required : true } ,
borrowRate : { type : String , required : true } ,
type : { type : String , required : true } ,
cf : { type : String , required : true } ,
borrowEnabled : { type : Boolean , default : true } ,
2021-08-06 22:44:51 +00:00
supplyRewardRate : { type : String , default : '0' } ,
borrowRewardRate : { type : String , default : '0' } ,
2021-07-21 22:08:46 +00:00
priceInUsd : { type : String , default : '0' } ,
} ,
setup ( props ) {
const { app } = useContext ( )
const { formatPercent , formatUsd , formatDecimal } = useFormatting ( )
2021-08-06 22:44:51 +00:00
const { showWarning } = useNotification ( )
2021-07-21 22:08:46 +00:00
const { isZero } = useBigNumber ( )
const { getTokenByKey } = useToken ( )
2021-08-06 22:44:51 +00:00
const rewardsSupported = computed ( ( ) => ! isZero ( props . supplyRewardRate ) && ! isZero ( props . borrowRewardRate ) )
2021-07-21 22:08:46 +00:00
const symbol = computed ( ( ) => getTokenByKey ( props . tokenKey ) ? . symbol || props . tokenKey )
function showSupply ( ) {
2021-08-06 22:44:51 +00:00
app . router . push ( { hash : ` supply?tokenId= ${ props . tokenId } ` } )
2021-07-21 22:08:46 +00:00
}
function showBorrow ( ) {
if ( props . borrowEnabled ) {
2021-08-06 22:44:51 +00:00
app . router . push ( { hash : ` borrow?tokenId= ${ props . tokenId } ` } )
2021-07-21 22:08:46 +00:00
} else {
2021-08-06 22:44:51 +00:00
showWarning ( 'Borrow Disabled' , ` Borrowing ${ props . tokenKey . toUpperCase ( ) } is disabled ` )
2021-07-21 22:08:46 +00:00
}
}
function showPayback ( ) {
2021-08-06 22:44:51 +00:00
app . router . push ( { hash : ` payback?tokenId= ${ props . tokenId } ` } )
2021-07-21 22:08:46 +00:00
}
function showWithdraw ( ) {
2021-08-06 22:44:51 +00:00
app . router . push ( { hash : ` withdraw?tokenId= ${ props . tokenId } ` } )
2021-07-21 22:08:46 +00:00
}
return {
showSupply ,
showBorrow ,
showPayback ,
showWithdraw ,
formatPercent ,
formatUsd ,
formatDecimal ,
2021-08-06 22:44:51 +00:00
rewardsSupported ,
2021-07-21 22:08:46 +00:00
symbol ,
}
} ,
} )
< / script >
< style scoped >
. position - button {
@ apply flex - 1 ;
@ apply h - 8 ;
@ apply h - 8 ;
}
< / style >