Skip to content
Snippets Groups Projects
Commit 3b487f7c authored by Hugo Trentesaux's avatar Hugo Trentesaux
Browse files

wip dynamic import for web3

parent fe367969
No related branches found
No related tags found
No related merge requests found
import type { ApiPromise } from '@polkadot/api' import type { ApiPromise } from '@polkadot/api'
import { web3FromAddress } from '@polkadot/extension-dapp'
import type { Vec, u32 } from '@polkadot/types-codec' import type { Vec, u32 } from '@polkadot/types-codec'
import type { ISubmittableResult, RegistryError } from '@polkadot/types/types' import type { ISubmittableResult, RegistryError } from '@polkadot/types/types'
import type { Ref } from 'vue' import type { Ref } from 'vue'
import { loginAccount } from './global' import { loginAccount } from './global'
import type { SubmittableExtrinsic } from '@polkadot/api/promise/types' import type { SubmittableExtrinsic } from '@polkadot/api/promise/types'
import type { AugmentedSubmittable } from '@polkadot/api-base/types'
/// fetch authorities /// fetch authorities
export function fetchAuthorities( export function fetchAuthorities(
...@@ -36,7 +34,9 @@ export async function signAndSend( ...@@ -36,7 +34,9 @@ export async function signAndSend(
successCallback: () => void successCallback: () => void
) { ) {
const address = loginAccount.value!.address const address = loginAccount.value!.address
const injector = await web3FromAddress(address) const injector = await import('@polkadot/extension-dapp').then((web3) =>
web3.web3FromAddress(address)
)
try { try {
await tx.signAndSend( await tx.signAndSend(
address, address,
......
...@@ -17,7 +17,6 @@ import type { ...@@ -17,7 +17,6 @@ import type {
import type { InjectedAccountWithMeta } from '@polkadot/extension-inject/types' import type { InjectedAccountWithMeta } from '@polkadot/extension-inject/types'
import type { ApiPromise } from '@polkadot/api' import type { ApiPromise } from '@polkadot/api'
import { type u32, Option } from '@polkadot/types-codec' import { type u32, Option } from '@polkadot/types-codec'
import { web3Accounts } from '@polkadot/extension-dapp'
import type { IdtyNameQuery } from '@/generated/squid' import type { IdtyNameQuery } from '@/generated/squid'
import { getItem, setItem, sk } from './storage' import { getItem, setItem, sk } from './storage'
import { IdtyName } from '@/squid/wot.gql' import { IdtyName } from '@/squid/wot.gql'
...@@ -31,7 +30,8 @@ export async function tryConnectAccount( ...@@ -31,7 +30,8 @@ export async function tryConnectAccount(
api: ApiPromise, api: ApiPromise,
apollo: ApolloClient<NormalizedCacheObject> apollo: ApolloClient<NormalizedCacheObject>
) { ) {
if (allAccounts.value.length == 0) allAccounts.value = await web3Accounts() if (allAccounts.value.length == 0)
allAccounts.value = await import('@polkadot/extension-dapp').then((web3) => web3.web3Accounts())
const allAcc = allAccounts.value const allAcc = allAccounts.value
allAccounts.value = allAcc allAccounts.value = allAcc
const defaultLogin = getItem<string>(sk.defaultAccount) const defaultLogin = getItem<string>(sk.defaultAccount)
......
...@@ -3,7 +3,6 @@ import { createApp } from 'vue' ...@@ -3,7 +3,6 @@ import { createApp } from 'vue'
import App from './App.vue' import App from './App.vue'
import router from './router' import router from './router'
import { initStateFromStorage, initStateFromApis } from './global' import { initStateFromStorage, initStateFromApis } from './global'
import { web3Enable } from '@polkadot/extension-dapp'
import { initLocalStorage } from './storage' import { initLocalStorage } from './storage'
import { initDatapod, initRpc, initSquid, initp2p } from './network' import { initDatapod, initRpc, initSquid, initp2p } from './network'
import { ApolloClients } from '@vue/apollo-composable' import { ApolloClients } from '@vue/apollo-composable'
...@@ -12,9 +11,6 @@ import { ApolloClients } from '@vue/apollo-composable' ...@@ -12,9 +11,6 @@ import { ApolloClients } from '@vue/apollo-composable'
initLocalStorage() initLocalStorage()
initStateFromStorage() initStateFromStorage()
// ask browser extension for web3 support
web3Enable('duniter-vue')
// ===== APP ===== // ===== APP =====
const app = createApp(App) const app = createApp(App)
...@@ -32,3 +28,7 @@ Promise.all([initRpc(), initSquid(), initDatapod()]).then(([api, apolloSquid, ap ...@@ -32,3 +28,7 @@ Promise.all([initRpc(), initSquid(), initDatapod()]).then(([api, apolloSquid, ap
// also provide datapod ipfs stack // also provide datapod ipfs stack
initp2p().then((p2p) => app.provide('p2p', p2p)) initp2p().then((p2p) => app.provide('p2p', p2p))
// === dynamic imports ===
// ask browser extension for web3 support
import('@polkadot/extension-dapp').then((web3) => web3.web3Enable('duniter-vue'))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment