Skip to content

Commit

Permalink
Merge pull request #1834 from /issues/1824
Browse files Browse the repository at this point in the history
Issues/1824
  • Loading branch information
Raj6939 authored Jan 6, 2023
2 parents 586f771 + ac50f0e commit 3217ac3
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 12 deletions.
10 changes: 6 additions & 4 deletions src/components/admin/marketPlaceSlider/marketPlaceSlide.vue
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ export default {
return {
/// TODO: Need to do it in a neat way
authToken: localStorage.getItem("authToken"),
accessToken:localStorage.getItem("accessToken"),
eventToAirdrop: {},
stickyNoteTitle: "💡 InfoBox",
selectedEvent: null,
Expand Down Expand Up @@ -396,7 +397,7 @@ export default {
else if (this.simpleData === "") {
throw new Error(this.notifyErr('Enter Wallet addresses and respective token value'))
}
const web3 = await loadweb3()
const web3 = await loadweb3(this.selectedChain)
const contract = new web3.eth.Contract(erc20ABI, this.depositTokenAddress);
this.feeStructure.symbol = await contract.methods.symbol().call();
console.log(this.simpleData)
Expand Down Expand Up @@ -453,7 +454,7 @@ export default {
if (this.proceed) {
try {
this.isLoading = true
const web3 = await loadweb3();
const web3 = await loadweb3(this.selectedChain);
this.accounts = await web3.eth.getAccounts();
const signerAddress = this.accounts[0]
const requestData = this.newData
Expand Down Expand Up @@ -512,13 +513,15 @@ export default {
parsedValue["externalRecordId"] = dbTreeId.toString()
parsedValue["contractAddress"] = this.depositTokenAddress.toString()
parsedValue["appBaseUrl"] = this.selectedTool.meta.appBaseUrl.toString()
parsedValue["chainId"] = this.selectedChain
console.log(parsedValue)
this.flash.value = JSON.stringify(parsedValue)
const index = this.eventToAirdrop.actions.findIndex((x) => {
return x._id === this.flash._id
})
if (index > -1) {
this.eventToAirdrop.actions[index] = this.flash
this.eventToAirdrop["isRewardDistribution"] = true
console.log(this.eventToAirdrop)
const url = `${this.$config.studioServer.BASE_URL}api/v1/project`;
let headers = {
Expand Down Expand Up @@ -591,8 +594,7 @@ export default {
async addMerkelTree(newRoot, ipfsHash, depositToken, tokenBalance) {
try {
console.log(newRoot, ipfsHash, depositToken, tokenBalance)
const web3 = await loadweb3();
console.log(web3);
const web3 = await loadweb3(this.selectedChain);
// this.accounts = await web3.eth.getAccounts();
// console.log(this.accounts);
const address = getAddress(parseInt(this.selectedChain))
Expand Down
4 changes: 2 additions & 2 deletions src/components/participant/Action.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Profile v-if="userProfile" :user="userProfile" :userReferralCount="userReferralCount" />

<template v-for="(actionItem, index) in ActionSchema">
<component v-if="actionItem.type==='INFO_TEXT'" :is="CapitaliseString(actionItem.type)" :key="index"
<component v-if="actionItem.type==='INFO_TEXT' && projectStatus === true" :is="CapitaliseString(actionItem.type)" :key="index"
:idValue="index" :data="actionItem" :done="actionItem.isDone" :authToken="authToken"
@input="updateUserInfo(actionItem, $event)" :themeData="themeData">
</component>
Expand All @@ -17,7 +17,7 @@
:eventId="eventId"/>
<template v-for="(actionItem, index) in ActionSchema">

<component v-if="(actionItem.type !== 'INFO_TEXT') && (actionItem.type !=='PRIZE_CARD') "
<component v-if="(actionItem.type !== 'INFO_TEXT') && (actionItem.type !=='PRIZE_CARD') && projectStatus === true"
:is="CapitaliseString(actionItem.type)" :key="index" :idValue="index" :data="actionItem" :authToken="authToken"
:done="actionItem.isDone" @input="updateUserInfo(actionItem, $event)" :themeData="themeData">
</component>
Expand Down
5 changes: 3 additions & 2 deletions src/components/participant/ActionInputs/RewardClaimAction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,8 @@ export default {
},
async importToken(data) {
this.isLoading = true;
const web3 = await loadweb3();
const chainIdFromData = JSON.parse(data.value).chainId
const web3 = await loadweb3(chainIdFromData);
const tokenAddress = JSON.parse(data.value).contractAddress;
const contract = new web3.eth.Contract(erc20ABI, tokenAddress);
const tokenSymbol = await contract.methods.symbol().call();
Expand Down Expand Up @@ -256,7 +257,7 @@ export default {
let data = [];
const parsedData = JSON.parse(row.value);
const airdropId = parsedData.externalRecordId;
const web3 = await loadweb3();
const web3 = await loadweb3(parsedData.chainId);
this.accounts = await web3.eth.getAccounts();
const url = `${parsedData.appBaseUrl}/bank/check/${this.accounts[0]}`;
const res = await axios.get(url);
Expand Down
84 changes: 81 additions & 3 deletions src/mixins/getWeb3.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,87 @@
import Web3 from 'web3'

async function loadWeb3() {
if(window.ethereum){
async function loadWeb3(inDecimal) {
if(window.ethereum){
const chain = Web3.utils.toHex(inDecimal);
window.web3 = new Web3(window.ethereum);
await window.ethereum.request({ method: "eth_requestAccounts" });
const chainIdd = await window.ethereum.request({ method: "eth_chainId" });
if(chainIdd !== chain){
try {
const res = await window.ethereum.request({
method:'wallet_switchEthereumChain',
params: [{ chainId: chain }],
})
console.log(res)
}catch(switchError) {
if(switchError.code === 4902) {
try{
switch (chain) {
case '0x1':
await window.ethereum.request({
method: "wallet_addEthereumChain",
params: [
{
chainId: "0x1",
chainName: "Ethereum Mainnet",
rpcUrls: [
"https://mainnet.infura.io/v3/",
],
blockExplorerUrls: ["https://etherscan.io"],
nativeCurrency: {
symbol: "ETH",
decimals: 18,
},
},
],
});
break
case '0x89':
await window.ethereum.request({
method: "wallet_addEthereumChain",
params: [
{
chainId: "0x89",
chainName: "Polygon mainnet",
rpcUrls: [
"https://polygon-rpc.com/",
],
blockExplorerUrls: ["https://polygonscan.com"],
nativeCurrency: {
symbol: "MATIC",
decimals: 18,
},
},
],
});
break
case '0x5':
await window.ethereum.request({
method: "wallet_addEthereumChain",
params: [
{
chainId: "0x5",
chainName: "Goerli test network",
rpcUrls: [
"https://goerli.infura.io/v3/",
],
blockExplorerUrls: ["https://goerli.etherscan.io"],
nativeCurrency: {
symbol: "GoerliETH",
decimals: 18,
},
},
],
});
break;
}

} catch(addError){
console.log(addError)
}
}
}
}
await window.ethereum.request({ method: "eth_requestAccounts" });
return window.web3;
}else if(window.web3){
window.web3 = new Web3(window.web3.currentProvider);
Expand Down
2 changes: 1 addition & 1 deletion src/views/admin/MarketPlace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<b-card-text>
MerkleHash based token airdrop tool for EVM compatible chains.
</b-card-text>
<footer>
<footer style="display:flex;">
<small>
<b-badge v-for="chain in tool.supportedChain" pill variant="secondary" style="margin-left: 2px">{{chain.name}}</b-badge>
</small>
Expand Down

0 comments on commit 3217ac3

Please sign in to comment.