mirror of
https://github.com/andrei0x309/clear-wallet.git
synced 2024-11-18 23:41:10 +00:00
comment: out debug msg
This commit is contained in:
parent
fecb21b550
commit
a206972dcd
@ -293,7 +293,7 @@ const listner = function(event: any) {
|
||||
try {
|
||||
if(event?.data?.data?.error){
|
||||
promResolvers.get(event.data.resId)?.reject(event.data.data);
|
||||
console.error(event?.data?.data)
|
||||
// console.error(event?.data?.data)
|
||||
}else {
|
||||
promResolvers.get(event.data.resId)?.resolve(event.data.data);
|
||||
}
|
||||
|
@ -450,7 +450,7 @@ const mainListner = (message: RequestArguments, sender:any, sendResponse: (a: an
|
||||
clearPk()
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
// console.error(e)
|
||||
sendResponse({
|
||||
error: true,
|
||||
code: rpcError.USER_REJECTED,
|
||||
|
@ -2,11 +2,13 @@
|
||||
<ion-page>
|
||||
<ion-header>
|
||||
<ion-toolbar>
|
||||
<ion-title>{{ isEdit ? 'Edit Network': 'Add Network' }}</ion-title>
|
||||
<ion-title>{{ isEdit ? "Edit Network" : "Add Network" }}</ion-title>
|
||||
</ion-toolbar>
|
||||
</ion-header>
|
||||
<ion-content class="ion-padding">
|
||||
<ion-button v-if="!isEdit" @click="templateModal=true" expand="block">Add from popular chain list</ion-button>
|
||||
<ion-button v-if="!isEdit" @click="templateModal = true" expand="block"
|
||||
>Add from popular chain list</ion-button
|
||||
>
|
||||
<ion-item>
|
||||
<ion-label>Name(*)</ion-label>
|
||||
<ion-input v-model="name" placeholder="ex: Polygon"></ion-input>
|
||||
@ -18,7 +20,11 @@
|
||||
<ion-item button>
|
||||
<ion-icon :icon="clipboardOutline" @click="paste('pasteRpc')" />
|
||||
<ion-label>RPC URL(*)</ion-label>
|
||||
<ion-input id="pasteRpc" placeholder="https://polygon-mainnet.g.alchemy.com/..." v-model="rpc" ></ion-input>
|
||||
<ion-input
|
||||
id="pasteRpc"
|
||||
placeholder="https://polygon-mainnet.g.alchemy.com/..."
|
||||
v-model="rpc"
|
||||
></ion-input>
|
||||
</ion-item>
|
||||
<ion-item button>
|
||||
<ion-icon :icon="clipboardOutline" @click="paste('pasteRpc')" />
|
||||
@ -28,11 +34,17 @@
|
||||
<ion-item button>
|
||||
<ion-icon :icon="clipboardOutline" @click="paste('pasteExplorer')" />
|
||||
<ion-label>Explorer(?)</ion-label>
|
||||
<ion-input id="pasteExplorer" placeholder="https://polygonscan.com" v-model="explorer" ></ion-input>
|
||||
<ion-input
|
||||
id="pasteExplorer"
|
||||
placeholder="https://polygonscan.com"
|
||||
v-model="explorer"
|
||||
></ion-input>
|
||||
</ion-item>
|
||||
<ion-item>
|
||||
<ion-button @click="onCancel">Cancel</ion-button>
|
||||
<ion-button @click="onAddNetwork">{{ isEdit ? 'Edit Network': 'Add Network' }}</ion-button>
|
||||
<ion-button @click="onAddNetwork">{{
|
||||
isEdit ? "Edit Network" : "Add Network"
|
||||
}}</ion-button>
|
||||
</ion-item>
|
||||
<ion-alert
|
||||
:is-open="alertOpen"
|
||||
@ -53,7 +65,7 @@
|
||||
</ion-toolbar>
|
||||
</ion-header>
|
||||
<ion-content class="ion-padding">
|
||||
<ion-list style="margin-bottom: 4rem;">
|
||||
<ion-list style="margin-bottom: 4rem">
|
||||
<ion-list-header>
|
||||
<ion-label>Networks</ion-label>
|
||||
</ion-list-header>
|
||||
@ -68,24 +80,37 @@
|
||||
</ion-segment>
|
||||
|
||||
<div v-if="currentSegment === 'mainnets'">
|
||||
<ion-list class="ion-padding" v-for="network of Object.values(mainNets)" :key="network.chainId">
|
||||
<ion-item button style="cursor:pointer;" @click="fillTemplate(network)">
|
||||
<ion-avatar style="margin-right: 1rem;">
|
||||
<img :alt="network.name" :src="getUrl('assets/chain-icons/' + network.icon)" />
|
||||
</ion-avatar><ion-label>{{network.name}}</ion-label>
|
||||
<ion-list
|
||||
class="ion-padding"
|
||||
v-for="network of Object.values(mainNets)"
|
||||
:key="network.chainId"
|
||||
>
|
||||
<ion-item button style="cursor: pointer" @click="fillTemplate(network)">
|
||||
<ion-avatar style="margin-right: 1rem">
|
||||
<img
|
||||
:alt="network.name"
|
||||
:src="getUrl('assets/chain-icons/' + network.icon)"
|
||||
/> </ion-avatar
|
||||
><ion-label>{{ network.name }}</ion-label>
|
||||
</ion-item>
|
||||
</ion-list>
|
||||
</div>
|
||||
<div v-else>
|
||||
<ion-list class="ion-padding" v-for="network of Object.values(testNets)" :key="network.chainId">
|
||||
<ion-item button style="cursor:pointer;" @click="fillTemplate(network)">
|
||||
<ion-avatar style="margin-right: 1rem;">
|
||||
<img :alt="network.name" :src="getUrl('assets/chain-icons/' + network.icon)" />
|
||||
</ion-avatar><ion-label>{{network.name}}</ion-label>
|
||||
<ion-list
|
||||
class="ion-padding"
|
||||
v-for="network of Object.values(testNets)"
|
||||
:key="network.chainId"
|
||||
>
|
||||
<ion-item button style="cursor: pointer" @click="fillTemplate(network)">
|
||||
<ion-avatar style="margin-right: 1rem">
|
||||
<img
|
||||
:alt="network.name"
|
||||
:src="getUrl('assets/chain-icons/' + network.icon)"
|
||||
/> </ion-avatar
|
||||
><ion-label>{{ network.name }}</ion-label>
|
||||
</ion-item>
|
||||
</ion-list>
|
||||
</div>
|
||||
|
||||
</ion-list>
|
||||
</ion-content>
|
||||
</ion-modal>
|
||||
@ -94,125 +119,167 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent, ref } from "vue";
|
||||
import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar, IonItem, IonLabel, IonInput, IonButton, IonIcon,
|
||||
IonModal, IonList, IonSegment, IonSegmentButton, IonListHeader, IonButtons, IonAvatar, modalController, IonAlert, onIonViewWillEnter
|
||||
import {
|
||||
IonContent,
|
||||
IonHeader,
|
||||
IonPage,
|
||||
IonTitle,
|
||||
IonToolbar,
|
||||
IonItem,
|
||||
IonLabel,
|
||||
IonInput,
|
||||
IonButton,
|
||||
IonIcon,
|
||||
IonModal,
|
||||
IonList,
|
||||
IonSegment,
|
||||
IonSegmentButton,
|
||||
IonListHeader,
|
||||
IonButtons,
|
||||
IonAvatar,
|
||||
modalController,
|
||||
IonAlert,
|
||||
onIonViewWillEnter,
|
||||
} from "@ionic/vue";
|
||||
import { getNetworks, saveSelectedNetwork, getUrl, paste, replaceNetworks } from "@/utils/platform";
|
||||
import {
|
||||
getNetworks,
|
||||
saveSelectedNetwork,
|
||||
getUrl,
|
||||
paste,
|
||||
replaceNetworks,
|
||||
} from "@/utils/platform";
|
||||
import router from "@/router";
|
||||
import { mainNets, testNets } from "@/utils/networks"
|
||||
import { useRoute } from 'vue-router'
|
||||
import { mainNets, testNets } from "@/utils/networks";
|
||||
import { useRoute } from "vue-router";
|
||||
import { clipboardOutline } from "ionicons/icons";
|
||||
import type { Networks, Network } from '@/extension/types'
|
||||
import type { Networks, Network } from "@/extension/types";
|
||||
|
||||
export default defineComponent({
|
||||
components: { IonContent, IonHeader, IonPage, IonTitle, IonToolbar, IonItem, IonLabel, IonInput, IonButton, IonIcon,
|
||||
IonModal, IonList, IonSegment, IonSegmentButton, IonListHeader, IonButtons, IonAvatar, IonAlert },
|
||||
components: {
|
||||
IonContent,
|
||||
IonHeader,
|
||||
IonPage,
|
||||
IonTitle,
|
||||
IonToolbar,
|
||||
IonItem,
|
||||
IonLabel,
|
||||
IonInput,
|
||||
IonButton,
|
||||
IonIcon,
|
||||
IonModal,
|
||||
IonList,
|
||||
IonSegment,
|
||||
IonSegmentButton,
|
||||
IonListHeader,
|
||||
IonButtons,
|
||||
IonAvatar,
|
||||
IonAlert,
|
||||
},
|
||||
setup: () => {
|
||||
const name = ref('')
|
||||
const chainId = ref(0)
|
||||
const rpc = ref('')
|
||||
const symbol = ref('')
|
||||
const explorer = ref('')
|
||||
const templateModal = ref(false)
|
||||
const currentSegment = ref('mainnets')
|
||||
const alertOpen = ref(false)
|
||||
const alertMsg = ref('')
|
||||
const route = useRoute()
|
||||
const isEdit = route.path.includes('/edit')
|
||||
const paramChainId = route.params.chainId ?? ""
|
||||
let networksProm: Promise<Networks | undefined>
|
||||
|
||||
const name = ref("");
|
||||
const chainId = ref(0);
|
||||
const rpc = ref("");
|
||||
const symbol = ref("");
|
||||
const explorer = ref("");
|
||||
const templateModal = ref(false);
|
||||
const currentSegment = ref("mainnets");
|
||||
const alertOpen = ref(false);
|
||||
const alertMsg = ref("");
|
||||
const route = useRoute();
|
||||
const isEdit = route.path.includes("/edit");
|
||||
const paramChainId = route.params.chainId ?? "";
|
||||
let networksProm: Promise<Networks | undefined>;
|
||||
|
||||
const fillNetworkInputs = (network: Network) => {
|
||||
name.value = network.name
|
||||
chainId.value = network.chainId
|
||||
rpc.value = network.rpc
|
||||
symbol.value = network.symbol ?? ''
|
||||
explorer.value = network.explorer ?? ''
|
||||
}
|
||||
name.value = network.name;
|
||||
chainId.value = network.chainId;
|
||||
rpc.value = network.rpc;
|
||||
symbol.value = network.symbol ?? "";
|
||||
explorer.value = network.explorer ?? "";
|
||||
};
|
||||
|
||||
onIonViewWillEnter(async () => {
|
||||
if (isEdit && paramChainId) {
|
||||
networksProm = getNetworks()
|
||||
const networks = await networksProm as Networks
|
||||
fillNetworkInputs(networks[Number(paramChainId)])
|
||||
networksProm = getNetworks();
|
||||
const networks = (await networksProm) as Networks;
|
||||
fillNetworkInputs(networks[Number(paramChainId)]);
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
const resetFields = () => {
|
||||
name.value = ''
|
||||
chainId.value = 0
|
||||
rpc.value = ''
|
||||
}
|
||||
name.value = "";
|
||||
chainId.value = 0;
|
||||
rpc.value = "";
|
||||
};
|
||||
|
||||
const onAddNetwork = async () => {
|
||||
if (Number(chainId.value) < 1) {
|
||||
alertMsg.value = "Chain Id must be a valid decimal integer"
|
||||
return alertOpen.value = true
|
||||
alertMsg.value = "Chain Id must be a valid decimal integer";
|
||||
return (alertOpen.value = true);
|
||||
}
|
||||
if (name.value.length < 2) {
|
||||
alertMsg.value = "Name must have at least 2 characters"
|
||||
return alertOpen.value = true
|
||||
alertMsg.value = "Name must have at least 2 characters";
|
||||
return (alertOpen.value = true);
|
||||
}
|
||||
if (name.value.length > 99) {
|
||||
alertMsg.value = "Name must be less than 100 characters"
|
||||
return alertOpen.value = true
|
||||
alertMsg.value = "Name must be less than 100 characters";
|
||||
return (alertOpen.value = true);
|
||||
}
|
||||
if (name.value.length > 99) {
|
||||
try {
|
||||
new URL(rpc.value)
|
||||
new URL(rpc.value);
|
||||
} catch {
|
||||
alertMsg.value = "RPC must be a valid URL"
|
||||
return alertOpen.value = true
|
||||
alertMsg.value = "RPC must be a valid URL";
|
||||
return (alertOpen.value = true);
|
||||
}
|
||||
}
|
||||
let p1 = Promise.resolve()
|
||||
let p1 = Promise.resolve();
|
||||
if (!networksProm) {
|
||||
networksProm = getNetworks()
|
||||
networksProm = getNetworks();
|
||||
}
|
||||
const networks = await networksProm as Networks
|
||||
const networks = (await networksProm) as Networks;
|
||||
const network = {
|
||||
name: name.value,
|
||||
chainId: chainId.value,
|
||||
rpc: rpc.value,
|
||||
...(symbol.value ? { symbol: symbol.value } : {}),
|
||||
...( explorer.value ? {explorer: explorer.value}:{})
|
||||
}
|
||||
...(explorer.value ? { explorer: explorer.value } : {}),
|
||||
};
|
||||
if ((Object.keys(networks).length ?? 0) < 1) {
|
||||
p1 = saveSelectedNetwork(network)
|
||||
p1 = saveSelectedNetwork(network);
|
||||
} else {
|
||||
if((chainId.value in networks) && !isEdit){
|
||||
alertMsg.value = "Network already exists."
|
||||
return alertOpen.value = true
|
||||
if (chainId.value in networks && !isEdit) {
|
||||
alertMsg.value = "Network already exists.";
|
||||
return (alertOpen.value = true);
|
||||
}
|
||||
}
|
||||
networks[chainId.value] = network
|
||||
const p2 = replaceNetworks(networks)
|
||||
await Promise.all([p1, p2])
|
||||
networks[chainId.value] = network;
|
||||
const p2 = replaceNetworks(networks);
|
||||
await Promise.all([p1, p2]);
|
||||
if (isEdit) {
|
||||
router.push('/tabs/networks')
|
||||
router.push("/tabs/networks");
|
||||
} else {
|
||||
router.push('/tabs/home')
|
||||
}
|
||||
resetFields()
|
||||
router.push("/tabs/home");
|
||||
}
|
||||
resetFields();
|
||||
};
|
||||
|
||||
const segmentChange = (value: any) => {
|
||||
currentSegment.value = value.detail.value
|
||||
}
|
||||
currentSegment.value = value.detail.value;
|
||||
};
|
||||
|
||||
const onCancel = () => {
|
||||
if (isEdit) {
|
||||
router.push('/tabs/networks')
|
||||
router.push("/tabs/networks");
|
||||
} else {
|
||||
router.push('/tabs/home')
|
||||
}
|
||||
router.push("/tabs/home");
|
||||
}
|
||||
};
|
||||
|
||||
const fillTemplate = (network: typeof mainNets[1]) => {
|
||||
fillNetworkInputs(network)
|
||||
modalController.dismiss(null, 'cancel')
|
||||
}
|
||||
fillNetworkInputs(network);
|
||||
modalController?.dismiss(null, "cancel");
|
||||
};
|
||||
|
||||
return {
|
||||
name,
|
||||
@ -233,9 +300,8 @@ export default defineComponent({
|
||||
alertMsg,
|
||||
symbol,
|
||||
explorer,
|
||||
isEdit
|
||||
}
|
||||
|
||||
}
|
||||
isEdit,
|
||||
};
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user