wc不再保存本地session
This commit is contained in:
parent
430e210bf6
commit
8cfc528f08
@ -1,5 +1,5 @@
|
||||
diff --git a/node_modules/@walletconnect/core/dist/esm/index.js b/node_modules/@walletconnect/core/dist/esm/index.js
|
||||
index a66eece..4668f0f 100644
|
||||
index a66eece..e6a79f4 100644
|
||||
--- a/node_modules/@walletconnect/core/dist/esm/index.js
|
||||
+++ b/node_modules/@walletconnect/core/dist/esm/index.js
|
||||
@@ -22,11 +22,16 @@ class Connector {
|
||||
@ -59,12 +59,25 @@ index a66eece..4668f0f 100644
|
||||
+ event: "socket_open",
|
||||
+ params: [],
|
||||
+ });
|
||||
+ self._transport.remove("open", sendOpenMsg)
|
||||
+ self._transport.remove("open", sendOpenMsg);
|
||||
+ }
|
||||
+ this._transport.on("open", sendOpenMsg);
|
||||
this._transport.open();
|
||||
}
|
||||
_formatUri() {
|
||||
@@ -867,9 +887,9 @@ class Connector {
|
||||
}
|
||||
_getStorageSession() {
|
||||
let result = null;
|
||||
- if (this._sessionStorage) {
|
||||
- result = this._sessionStorage.getSession();
|
||||
- }
|
||||
+ // if (this._sessionStorage) {
|
||||
+ // result = this._sessionStorage.getSession();
|
||||
+ // }
|
||||
return result;
|
||||
}
|
||||
_setStorageSession() {
|
||||
diff --git a/node_modules/@walletconnect/core/dist/esm/url.js b/node_modules/@walletconnect/core/dist/esm/url.js
|
||||
index d6da2b8..19202d5 100644
|
||||
--- a/node_modules/@walletconnect/core/dist/esm/url.js
|
||||
|
@ -1,56 +1,62 @@
|
||||
|
||||
import { IChainData } from '..'
|
||||
import WalletConnectProvider from '../lib/WalletConnectProvider'
|
||||
import { toHexChainId } from '../util/chain.util'
|
||||
import { IChainData } from "..";
|
||||
import WalletConnectProvider from "../lib/WalletConnectProvider";
|
||||
import { toHexChainId } from "../util/chain.util";
|
||||
|
||||
export class ZWalletConnect {
|
||||
provider: WalletConnectProvider
|
||||
accounts: string[] = []
|
||||
socketConnected = false
|
||||
provider: WalletConnectProvider;
|
||||
accounts: string[] = [];
|
||||
socketConnected = false;
|
||||
|
||||
constructor(rpc: any) {
|
||||
console.log('ZWalletConnect constructor');
|
||||
console.log("ZWalletConnect constructor");
|
||||
this.provider = new WalletConnectProvider({
|
||||
rpc,
|
||||
qrcodeModal: {
|
||||
open(uri: string, cb: any, opts?: any): void {
|
||||
console.log('walletconnect prepare jump to wallet: ' + uri)
|
||||
setTimeout(()=>{
|
||||
console.log("walletconnect prepare jump to wallet: " + uri);
|
||||
setTimeout(() => {
|
||||
// @ts-ignore
|
||||
jumpToWallet(uri)
|
||||
}, 1500)
|
||||
jumpToWallet(uri);
|
||||
}, 1500);
|
||||
//@ts-ignore
|
||||
// jumpToWallet(uri);
|
||||
},
|
||||
close(): void {
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
this._subscribeToEvents(this.provider)
|
||||
close(): void {},
|
||||
},
|
||||
});
|
||||
this._subscribeToEvents(this.provider);
|
||||
}
|
||||
|
||||
public async connect() {
|
||||
console.log('wallet connect begin connect')
|
||||
return this.provider.enable()
|
||||
console.log("wallet connect begin connect");
|
||||
return this.provider.enable();
|
||||
}
|
||||
|
||||
public async disconnect() {
|
||||
if (this.provider) {
|
||||
this.provider.removeListener("accountsChanged");
|
||||
this.provider.removeListener("chainChanged");
|
||||
this.provider.removeListener("disconnect");
|
||||
await this.provider.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
private _subscribeToEvents(provider: WalletConnectProvider) {
|
||||
this.provider.on('accountsChanged', async(accounts: string[]) => {
|
||||
console.log('accountsChanged: ', accounts)
|
||||
this.provider.on("accountsChanged", async (accounts: string[]) => {
|
||||
console.log("accountsChanged: ", accounts);
|
||||
this.accounts = accounts;
|
||||
})
|
||||
});
|
||||
|
||||
// Subscribe to chainId change
|
||||
this.provider.on('chainChanged', async(chainId: string) => {
|
||||
const chainIdNum = parseInt(chainId)
|
||||
console.log('chainChanged', chainId, chainIdNum)
|
||||
})
|
||||
this.provider.on("chainChanged", async (chainId: string) => {
|
||||
const chainIdNum = parseInt(chainId);
|
||||
console.log("chainChanged", chainId, chainIdNum);
|
||||
});
|
||||
|
||||
// Subscribe to session disconnection
|
||||
this.provider.on('disconnect', (err: any) => {
|
||||
console.log('disconnect', err)
|
||||
})
|
||||
this.provider.on("disconnect", (err: any) => {
|
||||
console.log("disconnect", err);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @param data
|
||||
@ -58,68 +64,70 @@ export class ZWalletConnect {
|
||||
public async addOrChangeChain(data: IChainData) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const onChainChange = (chainId: string) => {
|
||||
console.log('switchEthereumChain: ', chainId)
|
||||
this.provider.removeListener('chainChanged', onChainChange)
|
||||
console.log("switchEthereumChain: ", chainId);
|
||||
this.provider.removeListener("chainChanged", onChainChange);
|
||||
resolve && resolve(chainId);
|
||||
}
|
||||
this.provider.on('chainChanged', onChainChange)
|
||||
};
|
||||
this.provider.on("chainChanged", onChainChange);
|
||||
let params = {
|
||||
chainId: toHexChainId(data.id),
|
||||
chainName: data.name,
|
||||
nativeCurrency: {
|
||||
name: data.symbol,
|
||||
symbol: data.symbol,
|
||||
decimals: data.decimals || 18
|
||||
decimals: data.decimals || 18,
|
||||
},
|
||||
rpcUrls: [data.rpc],
|
||||
blockExplorerUrls: [data.explorerurl]
|
||||
}
|
||||
this.provider.request({
|
||||
method: 'wallet_addEthereumChain',
|
||||
params: [params]
|
||||
blockExplorerUrls: [data.explorerurl],
|
||||
};
|
||||
this.provider
|
||||
.request({
|
||||
method: "wallet_addEthereumChain",
|
||||
params: [params],
|
||||
})
|
||||
.then(() => {
|
||||
console.log('add chain success, wait result');
|
||||
console.log("add chain success, wait result");
|
||||
})
|
||||
.catch(err=>{
|
||||
console.error('add chain error: ', JSON.stringify(err));
|
||||
this.provider.removeListener('chainChanged', onChainChange);
|
||||
.catch((err) => {
|
||||
console.error("add chain error: ", JSON.stringify(err));
|
||||
this.provider.removeListener("chainChanged", onChainChange);
|
||||
reject && reject(err);
|
||||
})
|
||||
})
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public async signData(signObj: any, signer: string) {
|
||||
const msgParams = JSON.stringify(signObj)
|
||||
const from = signer || this.accounts[0]
|
||||
const msgParams = JSON.stringify(signObj);
|
||||
const from = signer || this.accounts[0];
|
||||
if (!from) {
|
||||
throw new Error('no account');
|
||||
throw new Error("no account");
|
||||
}
|
||||
console.log('sending personal sign req from', from, msgParams)
|
||||
const params = [from, msgParams]
|
||||
console.log("sending personal sign req from", from, msgParams);
|
||||
const params = [from, msgParams];
|
||||
const result: any = await this.sendCmd({
|
||||
method: 'eth_signTypedData_v4',
|
||||
method: "eth_signTypedData_v4",
|
||||
params,
|
||||
from
|
||||
})
|
||||
return result.result
|
||||
from,
|
||||
});
|
||||
return result.result;
|
||||
}
|
||||
|
||||
public async sendCmd({ method, params, from }: any) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.provider.sendAsync({
|
||||
this.provider.sendAsync(
|
||||
{
|
||||
method,
|
||||
params,
|
||||
from
|
||||
}, async function(err: any, result: any) {
|
||||
from,
|
||||
},
|
||||
async function (err: any, result: any) {
|
||||
if (err) {
|
||||
reject && reject(err)
|
||||
return
|
||||
reject && reject(err);
|
||||
return;
|
||||
}
|
||||
resolve && resolve(result)
|
||||
})
|
||||
})
|
||||
resolve && resolve(result);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -140,12 +140,14 @@ export default class JCWallet {
|
||||
*/
|
||||
public async initThirdPartyWallet() {
|
||||
this.walletType = WalletType.THIRD_PATH;
|
||||
return new Promise((resolve, reject) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
for (const d of AllChains) {
|
||||
const id = d.id;
|
||||
this.rpc[id] = d.rpc;
|
||||
}
|
||||
|
||||
if (this.wConnect) {
|
||||
this.wConnect.disconnect();
|
||||
}
|
||||
this.wConnect = new ZWalletConnect(this.rpc);
|
||||
// return this.wConnect.connect();
|
||||
this.wConnect
|
||||
|
Loading…
x
Reference in New Issue
Block a user