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