diff --git a/src/components/admin/marketPlaceSlider/marketPlaceSlide.vue b/src/components/admin/marketPlaceSlider/marketPlaceSlide.vue
index fe0dba83..852762dd 100644
--- a/src/components/admin/marketPlaceSlider/marketPlaceSlide.vue
+++ b/src/components/admin/marketPlaceSlider/marketPlaceSlide.vue
@@ -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,
@@ -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)
@@ -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
@@ -512,6 +513,7 @@ 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) => {
@@ -519,6 +521,7 @@ export default {
})
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 = {
@@ -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))
diff --git a/src/components/participant/Action.vue b/src/components/participant/Action.vue
index 5298f0d7..35005c78 100644
--- a/src/components/participant/Action.vue
+++ b/src/components/participant/Action.vue
@@ -5,7 +5,7 @@
-
@@ -17,7 +17,7 @@
:eventId="eventId"/>
-
diff --git a/src/components/participant/ActionInputs/RewardClaimAction.vue b/src/components/participant/ActionInputs/RewardClaimAction.vue
index a41b4928..88cd362f 100644
--- a/src/components/participant/ActionInputs/RewardClaimAction.vue
+++ b/src/components/participant/ActionInputs/RewardClaimAction.vue
@@ -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();
@@ -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);
diff --git a/src/mixins/getWeb3.js b/src/mixins/getWeb3.js
index f9cd9128..b1d183c8 100644
--- a/src/mixins/getWeb3.js
+++ b/src/mixins/getWeb3.js
@@ -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);
diff --git a/src/views/admin/MarketPlace.vue b/src/views/admin/MarketPlace.vue
index 11738697..0f5e7c27 100644
--- a/src/views/admin/MarketPlace.vue
+++ b/src/views/admin/MarketPlace.vue
@@ -87,7 +87,7 @@
MerkleHash based token airdrop tool for EVM compatible chains.
-