assembly/components/modal/web3/Web3Modal.vue

142 lines
4.5 KiB
Vue
Raw Normal View History

2021-08-31 19:23:47 +00:00
<template>
<div
2021-09-02 23:15:14 +00:00
class="relative inline-block w-full max-w-md px-8 py-8 overflow-hidden text-left align-bottom transition-all transform bg-white sm:my-16 sm:align-middle sm:p-6 "
:class="{
'border border-opacity-50 rounded-lg shadow-xl border-green-light': !slim
}"
2021-08-31 19:23:47 +00:00
role="dialog"
aria-modal="true"
aria-labelledby="modal-headline"
>
2021-09-02 23:15:14 +00:00
<div
:class="{
'py-8': !slim
}"
>
2021-09-02 22:19:19 +00:00
<div class="text-center">
<h3 id="modal-headline" class="font-bold text-2xl text-[#374253]">
2021-08-31 19:23:47 +00:00
Connect your wallet
</h3>
</div>
2021-09-02 22:19:19 +00:00
<div class="mt-8 w-full space-y-4">
<button
class="w-full px-6 py-3 text-left flex items-center h-[80px] border border-[#DBE5F4] rounded-[4px] text-lg text-[#374253] font-semibold hover:bg-background-light"
v-for="(wallet, key) in wallets"
2021-09-07 16:47:47 +00:00
:disabled="connecting"
2021-09-02 22:19:19 +00:00
:key="key"
@click="connect(wallet.connector)"
>
<div
style="background: radial-gradient(42.15% 42.15% at 48.94% 48.94%, #D6DAE0 75.67%, #F0F3F9 100%), #C4C4C4;"
class="mr-5 w-14 h-14 flex-shrink-0 rounded-full flex items-center justify-center border border-[#CCDCF3]"
>
<div
class="w-10 h-10 rounded-full inline-flex items-center justify-center bg-white"
>
<component :is="wallet.iconURL" class="w-7 h-7 text-white" />
</div>
</div>
{{ wallet.name }}
2021-08-31 19:23:47 +00:00
</button>
</div>
2021-09-02 22:19:19 +00:00
2021-09-05 22:40:07 +00:00
<div class="mt-6 text-center text-sm hidden">
2021-09-02 22:19:19 +00:00
Need help connecting a wallet?
<nuxt-link to="/faqs" class="font-semibold text-ocean-blue-pure"
>Read our FAQ</nuxt-link
>
</div>
2021-08-31 19:23:47 +00:00
</div>
2021-09-02 22:19:19 +00:00
2021-09-02 23:15:14 +00:00
<button v-if="!slim" class="absolute top-0 right-0 p-4" @click="close">
2021-09-02 22:19:19 +00:00
<svg
width="10"
height="10"
viewBox="0 0 10 10"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M0.279403 0.279336C-0.0930443 0.651784 -0.0930442 1.25564 0.279403 1.62809L3.65128 4.99997L0.279336 8.37191C-0.0931119 8.74436 -0.0931119 9.34822 0.279336 9.72066C0.651783 10.0931 1.25564 10.0931 1.62809 9.72066L5.00003 6.34872L8.37191 9.7206C8.74436 10.0931 9.34822 10.0931 9.72066 9.7206C10.0931 9.34816 10.0931 8.7443 9.72066 8.37185L6.34878 4.99997L9.7206 1.62815C10.093 1.2557 10.093 0.651844 9.7206 0.279396C9.34815 -0.0930521 8.74429 -0.093052 8.37184 0.279396L5.00003 3.65121L1.62816 0.279336C1.25571 -0.093112 0.651851 -0.093112 0.279403 0.279336Z"
fill="#1874FF"
/>
</svg>
</button>
2021-08-31 19:23:47 +00:00
</div>
</template>
<script>
2021-09-02 22:19:19 +00:00
import { computed, defineComponent, ref } from '@nuxtjs/composition-api'
2021-08-31 19:23:47 +00:00
import Input from '~/components/common/input/Input.vue'
import { useModal } from '~/composables/useModal'
2021-09-03 13:59:09 +00:00
import { useWeb3 } from '@instadapp/vue-web3'
2021-09-07 16:27:25 +00:00
import { injected, ledger } from '~/connectors'
2021-09-02 22:19:19 +00:00
import { SUPPORTED_WALLETS } from '~/constant/wallet'
2021-08-31 19:23:47 +00:00
import ButtonCTA from '../../common/input/ButtonCTA.vue'
import ButtonCTAOutlined from '../../common/input/ButtonCTAOutlined.vue'
2021-09-07 16:27:25 +00:00
import { Network, useNetwork } from '~/composables/useNetwork'
2021-09-07 16:44:11 +00:00
import { useNotification } from '~/composables/useNotification'
2021-08-31 19:23:47 +00:00
export default defineComponent({
2021-09-02 23:15:14 +00:00
props: {
slim: {
type: Boolean,
default: false
}
},
2021-08-31 19:23:47 +00:00
components: { ButtonCTA, ButtonCTAOutlined, Input },
setup() {
const { close } = useModal()
const { activate } = useWeb3()
2021-09-07 16:27:25 +00:00
const { activeNetworkId } = useNetwork()
2021-09-07 16:44:11 +00:00
const { showError, showAwaiting, closeAll } = useNotification()
2021-09-07 16:47:47 +00:00
const connecting = ref(false)
2021-08-31 19:23:47 +00:00
2021-09-02 22:19:19 +00:00
const connect = async (connector) => {
2021-09-07 16:47:47 +00:00
connecting.value = true
2021-09-07 16:44:11 +00:00
showAwaiting("Connecting...")
try {
await activate(connector, undefined, true)
2021-09-07 16:47:47 +00:00
connecting.value = false
2021-09-07 16:44:11 +00:00
close()
closeAll()
} catch (error) {
closeAll()
showError("", error.message)
}
2021-08-31 19:23:47 +00:00
2021-09-07 16:47:47 +00:00
connecting.value = false
2021-08-31 19:23:47 +00:00
}
2021-09-06 22:36:09 +00:00
const isMetamask = computed(() => process.server ? false : window.ethereum && window.ethereum.isMetaMask)
2021-09-02 22:19:19 +00:00
const wallets = computed(() => Object.keys(SUPPORTED_WALLETS).map((key) => {
const wallet = SUPPORTED_WALLETS[key]
if (wallet.connector === injected && !isMetamask.value) {
return null
}
2021-09-07 16:44:11 +00:00
if (wallet.connector === ledger && activeNetworkId.value !== Network.Mainnet) {
2021-09-07 16:27:25 +00:00
return null
}
2021-09-02 22:19:19 +00:00
return wallet
}).filter(Boolean))
2021-08-31 19:23:47 +00:00
return {
close,
2021-09-02 22:19:19 +00:00
connect,
wallets,
isMetamask,
injected,
2021-09-07 16:47:47 +00:00
connecting,
2021-08-31 19:23:47 +00:00
}
},
})
</script>