wallet connection fixes
This commit is contained in:
@@ -10,20 +10,24 @@
|
||||
<v-btn prepend-icon="mdi-reload" text="Reload After Installing Wallet" @click="reload"/>
|
||||
</p>
|
||||
</div>
|
||||
<!--
|
||||
<div v-if="walletOk && !providerOk">
|
||||
<p>
|
||||
Please log in to your crypto wallet.
|
||||
Please switch to a supported blockchain.
|
||||
</p>
|
||||
<v-btn prepend-icon="mdi-power" text="Connect Wallet" @click="connectWallet"/>
|
||||
<v-btn prepend-icon="mdi-power" text="Switch Blockchain" @click="switchChain(s.chainId)"/>
|
||||
</div>
|
||||
<div v-if="walletOk && chainOk && !providerOk">
|
||||
<!-- todo Alpha Live
|
||||
-->
|
||||
<div v-if="walletOk && !providerOk">
|
||||
TODO
|
||||
<!--
|
||||
<!– todo Alpha Live
|
||||
<v-card-title><v-icon icon="mdi-reload-alert" color="warning"/> Change Blockchain</v-card-title>
|
||||
<v-card-text>
|
||||
Dexorder works only with <blockchain chain-id="42161"/>. Please switch to the
|
||||
<blockchain chain-id="42161"/> blockchain in your wallet.
|
||||
</v-card-text>
|
||||
-->
|
||||
–>
|
||||
<h2><v-icon icon="mdi-hand-wave" color="warning"/> Welcome to Dexorder Alpha!</h2>
|
||||
<p>
|
||||
This alpha test runs on the Dexorder Testnet blockchain, which gives you free testnet tokens to trade.
|
||||
@@ -52,54 +56,42 @@
|
||||
Open Metamask again and select the "Dexorder Alpha" blockchain for use with this website.
|
||||
</li>
|
||||
</ol>
|
||||
-->
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {useStore} from "@/store/store";
|
||||
import PhoneCard from "@/components/PhoneCard.vue";
|
||||
import {connectWallet} from "@/blockchain/wallet.js";
|
||||
import {computed, watch} from "vue";
|
||||
import Blockchain from "@/components/Blockchain.vue";
|
||||
import {switchChain, useWalletStore} from "@/blockchain/wallet.js";
|
||||
import {computed, ref, watchEffect} from "vue";
|
||||
|
||||
const s = useStore()
|
||||
const ws = useWalletStore()
|
||||
const walletOk = typeof window.ethereum !== 'undefined'
|
||||
const providerOk = computed(()=>s.provider!==null)
|
||||
const chainOk = computed(()=>providerOk.value && s.helper!==null)
|
||||
const ok = computed(()=>walletOk && providerOk.value && chainOk.value)
|
||||
const providerOk = computed(()=>ws.chainId === s.chainId)
|
||||
const ok = computed(()=>walletOk && providerOk.value)
|
||||
const connecting = ref(false)
|
||||
|
||||
watchEffect(()=>{
|
||||
if( !providerOk.value && connecting.value ) {
|
||||
try {
|
||||
switchChain(s.chainId)
|
||||
}
|
||||
catch (e) {
|
||||
console.log('switchChain failed', e)
|
||||
if (e.code===-9999999) {
|
||||
// todo
|
||||
addTestnet()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
function reload() {
|
||||
window.location.reload()
|
||||
}
|
||||
|
||||
async function addChain() {
|
||||
await window.ethereum.request({
|
||||
"method": "wallet_addEthereumChain",
|
||||
"params": [
|
||||
{
|
||||
"chainId": "0x539",
|
||||
"chainName": "Dexorder Alpha Testnet",
|
||||
"rpcUrls": ["https://rpc.alpha.dexorder.trade"],
|
||||
"nativeCurrency": {
|
||||
"name": "Test Ethereum",
|
||||
"symbol": "TETH",
|
||||
"decimals": 18
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
watch([providerOk, chainOk], async () => {
|
||||
console.log('checking chain')
|
||||
if (walletOk && providerOk.value && !chainOk.value) {
|
||||
console.log('switching chain')
|
||||
const result = await window.ethereum.request({
|
||||
"method": "wallet_switchEthereumChain",
|
||||
"params": [{"chainId": '0x' + Object.keys(metadata)[0].toString(16)}]
|
||||
});
|
||||
console.log('chain switch result', result)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
Reference in New Issue
Block a user