Skip to content

Instantly share code, notes, and snippets.

@owenvoke
Last active June 13, 2018 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owenvoke/9f6b4e0b742d96e1a60783d74409b8d1 to your computer and use it in GitHub Desktop.
Save owenvoke/9f6b4e0b742d96e1a60783d74409b8d1 to your computer and use it in GitHub Desktop.

CoinLib Vue Component

Usage

Common Coins

For common coins, simply set the coin property to the short code of the coin (e.g. btc for Bitcoin).

<coin-lib-vue coin="eth"></coin-lib-vue>

Custom Coins

Below is an example for 0x (ZRX) with id 386.

<coin-lib-vue coin="386"></coin-lib-vue>

Dark Theme

Use the is-dark property to use the dark theme.

<coin-lib-vue is-dark coin="bch"></coin-lib-vue>
<template>
<div :class="{ 'coinlib-vue': true, 'is-dark': isDark }">
<iframe :src="iframeUrl" sandbox="allow-same-origin allow-scripts"></iframe>
<span class="powered-by">
<span>powered by&nbsp;</span>
<a :href="coinLibUri" target="_blank">CoinLib</a>
</span>
</div>
</template>
<script>
const COMMON_COINS = {
btc: 859, // Bitcoin
eth: 145, // Ethereum
xrp: 619, // Ripple
bch: 157, // Bitcoin Cash
aro: 896503 // Arionum
}
export default {
name: 'CoinLib',
data: function () {
return {
coinLibUri: 'https://coinlib.io'
}
},
props: {
isDark: Boolean,
coin: String
},
computed: {
iframeUrl () {
let theme = this.isDark ? 'dark' : 'light'
return `${this.coinLibUri}/widget?type=single&theme=${theme}&coin_id=${this.coinId}`
},
coinId () {
return (COMMON_COINS[this.coin] !== undefined) ? COMMON_COINS[this.coin] : this.coin
}
}
}
</script>
<style lang="scss" scoped>
.coinlib-vue {
font-family: sans-serif;
width: 220px;
height: 175px;
border: 1px solid #ddd;
border-radius: 10%;
&.is-dark {
background: #1d2330;
color: #fff;
}
iframe {
overflow: hidden;
border: none;
border-radius: 10%;
margin: 0;
padding: 0;
width: 100%;
height: 85%;
}
.powered-by {
float: right;
margin-right: 5%;
font-size: 0.6em;
a {
color: #4791b4;
text-decoration: none;
}
}
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment