@interchain-kit/react 0.3.18 → 0.3.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/hooks/useChain.js +1 -6
- package/esm/hooks/useChainWallet.js +1 -6
- package/esm/store/store.js +73 -2
- package/esm/utils/safeStrictBatchPatch.js +26 -0
- package/hooks/useChain.js +1 -6
- package/hooks/useChainWallet.js +1 -6
- package/package.json +7 -6
- package/store/store.d.ts +1 -0
- package/store/store.js +72 -1
- package/utils/safeStrictBatchPatch.d.ts +8 -0
- package/utils/safeStrictBatchPatch.js +29 -0
package/esm/hooks/useChain.js
CHANGED
|
@@ -2,7 +2,6 @@ import { useWalletModal } from "../modal";
|
|
|
2
2
|
import { useWalletManager } from './useWalletManager';
|
|
3
3
|
import { ChainNameNotExist } from '@interchain-kit/core';
|
|
4
4
|
import { useSigningClient } from './useSigningClient';
|
|
5
|
-
import { decorateWallet } from '../utils/decorateWallet';
|
|
6
5
|
export const useChain = (chainName) => {
|
|
7
6
|
const { assetLists, currentWalletName, disconnect, setCurrentChainName, getChainByName, getWalletByName, getChainWalletState, getChainLogoUrl, connect, getSigningClient, getRpcEndpoint, getAccount } = useWalletManager();
|
|
8
7
|
const chain = getChainByName(chainName);
|
|
@@ -35,11 +34,7 @@ export const useChain = (chainName) => {
|
|
|
35
34
|
chain,
|
|
36
35
|
assetList,
|
|
37
36
|
address: chainWalletStateToShow?.account?.address,
|
|
38
|
-
wallet
|
|
39
|
-
connect: () => connect(currentWalletName, chainName),
|
|
40
|
-
disconnect: () => disconnect(currentWalletName, chainName),
|
|
41
|
-
getAccount: () => getAccount(currentWalletName, chainName),
|
|
42
|
-
}) : null,
|
|
37
|
+
wallet,
|
|
43
38
|
getSigningClient: () => getSigningClient(currentWalletName, chainName),
|
|
44
39
|
signingClient,
|
|
45
40
|
isSigningClientLoading,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { useWalletManager } from "./useWalletManager";
|
|
2
2
|
import { useSigningClient } from "./useSigningClient";
|
|
3
|
-
import { decorateWallet } from "../utils/decorateWallet";
|
|
4
3
|
export const useChainWallet = (chainName, walletName) => {
|
|
5
4
|
const { assetLists, disconnect, setCurrentChainName, setCurrentWalletName, getChainByName, getWalletByName, getChainWalletState, getChainLogoUrl, connect, getSigningClient, getRpcEndpoint, getAccount } = useWalletManager();
|
|
6
5
|
const chain = getChainByName(chainName);
|
|
@@ -25,11 +24,7 @@ export const useChainWallet = (chainName, walletName) => {
|
|
|
25
24
|
chain,
|
|
26
25
|
assetList,
|
|
27
26
|
address: chainWalletStateToShow?.account?.address,
|
|
28
|
-
wallet
|
|
29
|
-
connect: () => connect(walletName, chainName),
|
|
30
|
-
disconnect: () => disconnect(walletName, chainName),
|
|
31
|
-
getAccount: () => getAccount(walletName, chainName),
|
|
32
|
-
}) : null,
|
|
27
|
+
wallet,
|
|
33
28
|
getSigningClient: () => getSigningClient(walletName, chainName),
|
|
34
29
|
signingClient,
|
|
35
30
|
isSigningClientLoading,
|
package/esm/store/store.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { clientNotExistError, WalletState } from "@interchain-kit/core";
|
|
1
|
+
import { clientNotExistError, WalletState, WCWallet } from "@interchain-kit/core";
|
|
2
2
|
import { createStore } from "zustand";
|
|
3
3
|
import { immer } from "zustand/middleware/immer";
|
|
4
4
|
import { persist, createJSONStorage } from 'zustand/middleware';
|
|
5
5
|
import { dedupeAsync } from '../utils';
|
|
6
|
+
import { decorateWallet } from '../utils/decorateWallet';
|
|
6
7
|
const immerSyncUp = (newWalletManager) => {
|
|
7
8
|
return (draft) => {
|
|
8
9
|
draft.chains = newWalletManager.chains;
|
|
@@ -24,7 +25,7 @@ export const createInterchainStore = (walletManager) => {
|
|
|
24
25
|
currentChainName: '',
|
|
25
26
|
chains: [...walletManager.chains],
|
|
26
27
|
assetLists: [...walletManager.assetLists],
|
|
27
|
-
wallets:
|
|
28
|
+
wallets: [],
|
|
28
29
|
signerOptions: walletManager.signerOptions,
|
|
29
30
|
endpointOptions: walletManager.endpointOptions,
|
|
30
31
|
preferredSignTypeMap: { ...walletManager.preferredSignTypeMap },
|
|
@@ -38,7 +39,77 @@ export const createInterchainStore = (walletManager) => {
|
|
|
38
39
|
draft.chainWalletState[targetIndex] = { ...draft.chainWalletState[targetIndex], ...data };
|
|
39
40
|
});
|
|
40
41
|
},
|
|
42
|
+
createStatefulWallet: () => {
|
|
43
|
+
const wallets = walletManager.wallets.map(wallet => {
|
|
44
|
+
decorateWallet(wallet, {
|
|
45
|
+
connect: async (chainId) => {
|
|
46
|
+
const walletName = wallet.info.name;
|
|
47
|
+
const chainName = get().chains.find(chain => chain.chainId === chainId)?.chainName;
|
|
48
|
+
const state = get().getChainWalletState(walletName, chainName)?.walletState;
|
|
49
|
+
if (state === WalletState.NotExist) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (walletName === 'WalletConnect' && state === WalletState.Connected) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
set(draft => {
|
|
56
|
+
draft.currentChainName = chainName;
|
|
57
|
+
draft.currentWalletName = walletName;
|
|
58
|
+
draft.walletConnectQRCodeUri = '';
|
|
59
|
+
});
|
|
60
|
+
get().updateChainWalletState(walletName, chainName, { walletState: WalletState.Connecting, errorMessage: '' });
|
|
61
|
+
try {
|
|
62
|
+
if (wallet instanceof WCWallet) {
|
|
63
|
+
wallet.setOnPairingUriCreatedCallback((uri) => {
|
|
64
|
+
set(draft => {
|
|
65
|
+
draft.walletConnectQRCodeUri = uri;
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
await wallet.connect(chainId);
|
|
70
|
+
get().updateChainWalletState(walletName, chainName, { walletState: WalletState.Connected });
|
|
71
|
+
await get().getAccount(walletName, chainName);
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
if (error.message === 'Request rejected') {
|
|
75
|
+
get().updateChainWalletState(walletName, chainName, { walletState: WalletState.Rejected, errorMessage: error.message });
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
get().updateChainWalletState(walletName, chainName, { walletState: WalletState.Disconnected, errorMessage: error.message });
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
disconnect: async (chainId) => {
|
|
82
|
+
const walletName = wallet.info.name;
|
|
83
|
+
const chainName = get().chains.find(chain => chain.chainId === chainId)?.chainName;
|
|
84
|
+
try {
|
|
85
|
+
await wallet.disconnect(chainId);
|
|
86
|
+
get().updateChainWalletState(walletName, chainName, { walletState: WalletState.Disconnected, account: null });
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
getAccount: async (chainId) => {
|
|
92
|
+
const walletName = wallet.info.name;
|
|
93
|
+
const chainName = get().chains.find(chain => chain.chainId === chainId)?.chainName;
|
|
94
|
+
try {
|
|
95
|
+
const account = await wallet.getAccount(chainId);
|
|
96
|
+
get().updateChainWalletState(walletName, chainName, { account });
|
|
97
|
+
return account;
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
console.log(error);
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
walletState: get().chainWalletState.find(cws => cws.walletName === wallet.info.name && cws.chainName === get().currentChainName)?.walletState || WalletState.Disconnected,
|
|
104
|
+
});
|
|
105
|
+
return wallet;
|
|
106
|
+
});
|
|
107
|
+
set(draft => {
|
|
108
|
+
draft.wallets = wallets;
|
|
109
|
+
});
|
|
110
|
+
},
|
|
41
111
|
init: async () => {
|
|
112
|
+
get().createStatefulWallet();
|
|
42
113
|
const oldChainWalletStatesMap = new Map(get().chainWalletState.map(cws => [cws.walletName + cws.chainName, cws]));
|
|
43
114
|
// should remove wallet that already disconnected ,for hydrain back from localstorage
|
|
44
115
|
// const oldChainWalletStateMap = new Map()
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export function safeStrictBatchPatch(target, patches) {
|
|
2
|
+
Object.keys(patches).forEach((key) => {
|
|
3
|
+
const patch = patches[key];
|
|
4
|
+
const original = target[key];
|
|
5
|
+
const isDescriptor = patch && typeof patch === 'object' &&
|
|
6
|
+
(typeof patch.get === 'function' ||
|
|
7
|
+
typeof patch.set === 'function');
|
|
8
|
+
if (isDescriptor) {
|
|
9
|
+
const descriptor = patch;
|
|
10
|
+
const originalDescriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
11
|
+
Object.defineProperty(target, key, {
|
|
12
|
+
configurable: true,
|
|
13
|
+
enumerable: originalDescriptor ? originalDescriptor.enumerable : true,
|
|
14
|
+
...descriptor
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
else if (typeof original === 'function' && typeof patch === 'function') {
|
|
18
|
+
target[key] = function (...args) {
|
|
19
|
+
return patch.call(this, original.bind(this), ...args);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
target[key] = patch;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
package/hooks/useChain.js
CHANGED
|
@@ -5,7 +5,6 @@ const modal_1 = require("../modal");
|
|
|
5
5
|
const useWalletManager_1 = require("./useWalletManager");
|
|
6
6
|
const core_1 = require("@interchain-kit/core");
|
|
7
7
|
const useSigningClient_1 = require("./useSigningClient");
|
|
8
|
-
const decorateWallet_1 = require("../utils/decorateWallet");
|
|
9
8
|
const useChain = (chainName) => {
|
|
10
9
|
const { assetLists, currentWalletName, disconnect, setCurrentChainName, getChainByName, getWalletByName, getChainWalletState, getChainLogoUrl, connect, getSigningClient, getRpcEndpoint, getAccount } = (0, useWalletManager_1.useWalletManager)();
|
|
11
10
|
const chain = getChainByName(chainName);
|
|
@@ -38,11 +37,7 @@ const useChain = (chainName) => {
|
|
|
38
37
|
chain,
|
|
39
38
|
assetList,
|
|
40
39
|
address: chainWalletStateToShow?.account?.address,
|
|
41
|
-
wallet
|
|
42
|
-
connect: () => connect(currentWalletName, chainName),
|
|
43
|
-
disconnect: () => disconnect(currentWalletName, chainName),
|
|
44
|
-
getAccount: () => getAccount(currentWalletName, chainName),
|
|
45
|
-
}) : null,
|
|
40
|
+
wallet,
|
|
46
41
|
getSigningClient: () => getSigningClient(currentWalletName, chainName),
|
|
47
42
|
signingClient,
|
|
48
43
|
isSigningClientLoading,
|
package/hooks/useChainWallet.js
CHANGED
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useChainWallet = void 0;
|
|
4
4
|
const useWalletManager_1 = require("./useWalletManager");
|
|
5
5
|
const useSigningClient_1 = require("./useSigningClient");
|
|
6
|
-
const decorateWallet_1 = require("../utils/decorateWallet");
|
|
7
6
|
const useChainWallet = (chainName, walletName) => {
|
|
8
7
|
const { assetLists, disconnect, setCurrentChainName, setCurrentWalletName, getChainByName, getWalletByName, getChainWalletState, getChainLogoUrl, connect, getSigningClient, getRpcEndpoint, getAccount } = (0, useWalletManager_1.useWalletManager)();
|
|
9
8
|
const chain = getChainByName(chainName);
|
|
@@ -28,11 +27,7 @@ const useChainWallet = (chainName, walletName) => {
|
|
|
28
27
|
chain,
|
|
29
28
|
assetList,
|
|
30
29
|
address: chainWalletStateToShow?.account?.address,
|
|
31
|
-
wallet
|
|
32
|
-
connect: () => connect(walletName, chainName),
|
|
33
|
-
disconnect: () => disconnect(walletName, chainName),
|
|
34
|
-
getAccount: () => getAccount(walletName, chainName),
|
|
35
|
-
}) : null,
|
|
30
|
+
wallet,
|
|
36
31
|
getSigningClient: () => getSigningClient(walletName, chainName),
|
|
37
32
|
signingClient,
|
|
38
33
|
isSigningClientLoading,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@interchain-kit/react",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.19",
|
|
4
4
|
"author": "Hyperweb <developers@hyperweb.io>",
|
|
5
5
|
"description": "interchain-kit wallet connector react package",
|
|
6
6
|
"main": "index.js",
|
|
@@ -34,13 +34,14 @@
|
|
|
34
34
|
"keywords": [],
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@chain-registry/v2-types": "^0.53.40",
|
|
37
|
-
"@interchain-kit/core": "0.3.
|
|
37
|
+
"@interchain-kit/core": "0.3.19",
|
|
38
38
|
"@interchain-ui/react": "1.26.1",
|
|
39
|
-
"@interchainjs/cosmos": "1.11.
|
|
40
|
-
"@interchainjs/cosmos-types": "1.11.
|
|
39
|
+
"@interchainjs/cosmos": "1.11.9",
|
|
40
|
+
"@interchainjs/cosmos-types": "1.11.9",
|
|
41
|
+
"@interchainjs/types": "1.11.9",
|
|
41
42
|
"@react-icons/all-files": "^4.1.0",
|
|
42
43
|
"@walletconnect/types": "^2.17.3",
|
|
43
|
-
"interchainjs": "1.11.
|
|
44
|
+
"interchainjs": "1.11.9",
|
|
44
45
|
"zustand": "^5.0.3"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
@@ -63,5 +64,5 @@
|
|
|
63
64
|
"react": "^19.0.0",
|
|
64
65
|
"react-dom": "^19.0.0"
|
|
65
66
|
},
|
|
66
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "ac174d991823da57deca18cb47e79730a80e3706"
|
|
67
68
|
}
|
package/store/store.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ export interface InterchainStore extends WalletManager {
|
|
|
19
19
|
getDraftChainWalletState: (state: InterchainStore, walletName: string, chainName: string) => ChainWalletState;
|
|
20
20
|
getChainWalletState: (walletName: string, chainName: string) => ChainWalletState | undefined;
|
|
21
21
|
updateChainWalletState: (walletName: string, chainName: string, data: Partial<ChainWalletState>) => void;
|
|
22
|
+
createStatefulWallet: () => void;
|
|
22
23
|
isReady: boolean;
|
|
23
24
|
}
|
|
24
25
|
export type InterchainStoreData = {
|
package/store/store.js
CHANGED
|
@@ -6,6 +6,7 @@ const zustand_1 = require("zustand");
|
|
|
6
6
|
const immer_1 = require("zustand/middleware/immer");
|
|
7
7
|
const middleware_1 = require("zustand/middleware");
|
|
8
8
|
const utils_1 = require("../utils");
|
|
9
|
+
const decorateWallet_1 = require("../utils/decorateWallet");
|
|
9
10
|
const immerSyncUp = (newWalletManager) => {
|
|
10
11
|
return (draft) => {
|
|
11
12
|
draft.chains = newWalletManager.chains;
|
|
@@ -27,7 +28,7 @@ const createInterchainStore = (walletManager) => {
|
|
|
27
28
|
currentChainName: '',
|
|
28
29
|
chains: [...walletManager.chains],
|
|
29
30
|
assetLists: [...walletManager.assetLists],
|
|
30
|
-
wallets:
|
|
31
|
+
wallets: [],
|
|
31
32
|
signerOptions: walletManager.signerOptions,
|
|
32
33
|
endpointOptions: walletManager.endpointOptions,
|
|
33
34
|
preferredSignTypeMap: { ...walletManager.preferredSignTypeMap },
|
|
@@ -41,7 +42,77 @@ const createInterchainStore = (walletManager) => {
|
|
|
41
42
|
draft.chainWalletState[targetIndex] = { ...draft.chainWalletState[targetIndex], ...data };
|
|
42
43
|
});
|
|
43
44
|
},
|
|
45
|
+
createStatefulWallet: () => {
|
|
46
|
+
const wallets = walletManager.wallets.map(wallet => {
|
|
47
|
+
(0, decorateWallet_1.decorateWallet)(wallet, {
|
|
48
|
+
connect: async (chainId) => {
|
|
49
|
+
const walletName = wallet.info.name;
|
|
50
|
+
const chainName = get().chains.find(chain => chain.chainId === chainId)?.chainName;
|
|
51
|
+
const state = get().getChainWalletState(walletName, chainName)?.walletState;
|
|
52
|
+
if (state === core_1.WalletState.NotExist) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (walletName === 'WalletConnect' && state === core_1.WalletState.Connected) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
set(draft => {
|
|
59
|
+
draft.currentChainName = chainName;
|
|
60
|
+
draft.currentWalletName = walletName;
|
|
61
|
+
draft.walletConnectQRCodeUri = '';
|
|
62
|
+
});
|
|
63
|
+
get().updateChainWalletState(walletName, chainName, { walletState: core_1.WalletState.Connecting, errorMessage: '' });
|
|
64
|
+
try {
|
|
65
|
+
if (wallet instanceof core_1.WCWallet) {
|
|
66
|
+
wallet.setOnPairingUriCreatedCallback((uri) => {
|
|
67
|
+
set(draft => {
|
|
68
|
+
draft.walletConnectQRCodeUri = uri;
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
await wallet.connect(chainId);
|
|
73
|
+
get().updateChainWalletState(walletName, chainName, { walletState: core_1.WalletState.Connected });
|
|
74
|
+
await get().getAccount(walletName, chainName);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (error.message === 'Request rejected') {
|
|
78
|
+
get().updateChainWalletState(walletName, chainName, { walletState: core_1.WalletState.Rejected, errorMessage: error.message });
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
get().updateChainWalletState(walletName, chainName, { walletState: core_1.WalletState.Disconnected, errorMessage: error.message });
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
disconnect: async (chainId) => {
|
|
85
|
+
const walletName = wallet.info.name;
|
|
86
|
+
const chainName = get().chains.find(chain => chain.chainId === chainId)?.chainName;
|
|
87
|
+
try {
|
|
88
|
+
await wallet.disconnect(chainId);
|
|
89
|
+
get().updateChainWalletState(walletName, chainName, { walletState: core_1.WalletState.Disconnected, account: null });
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
getAccount: async (chainId) => {
|
|
95
|
+
const walletName = wallet.info.name;
|
|
96
|
+
const chainName = get().chains.find(chain => chain.chainId === chainId)?.chainName;
|
|
97
|
+
try {
|
|
98
|
+
const account = await wallet.getAccount(chainId);
|
|
99
|
+
get().updateChainWalletState(walletName, chainName, { account });
|
|
100
|
+
return account;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
console.log(error);
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
walletState: get().chainWalletState.find(cws => cws.walletName === wallet.info.name && cws.chainName === get().currentChainName)?.walletState || core_1.WalletState.Disconnected,
|
|
107
|
+
});
|
|
108
|
+
return wallet;
|
|
109
|
+
});
|
|
110
|
+
set(draft => {
|
|
111
|
+
draft.wallets = wallets;
|
|
112
|
+
});
|
|
113
|
+
},
|
|
44
114
|
init: async () => {
|
|
115
|
+
get().createStatefulWallet();
|
|
45
116
|
const oldChainWalletStatesMap = new Map(get().chainWalletState.map(cws => [cws.walletName + cws.chainName, cws]));
|
|
46
117
|
// should remove wallet that already disconnected ,for hydrain back from localstorage
|
|
47
118
|
// const oldChainWalletStateMap = new Map()
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type MethodPatch<T, K extends keyof T> = T[K] extends (...args: any[]) => any ? (original: T[K], ...args: Parameters<T[K]>) => ReturnType<T[K]> : never;
|
|
2
|
+
type PropertyPatch<T, K extends keyof T> = T[K];
|
|
3
|
+
type DescriptorPatch = PropertyDescriptor;
|
|
4
|
+
type PatchConfig<T> = {
|
|
5
|
+
[K in keyof T]?: MethodPatch<T, K> | PropertyPatch<T, K> | DescriptorPatch;
|
|
6
|
+
};
|
|
7
|
+
export declare function safeStrictBatchPatch<T>(target: T, patches: PatchConfig<T>): void;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.safeStrictBatchPatch = safeStrictBatchPatch;
|
|
4
|
+
function safeStrictBatchPatch(target, patches) {
|
|
5
|
+
Object.keys(patches).forEach((key) => {
|
|
6
|
+
const patch = patches[key];
|
|
7
|
+
const original = target[key];
|
|
8
|
+
const isDescriptor = patch && typeof patch === 'object' &&
|
|
9
|
+
(typeof patch.get === 'function' ||
|
|
10
|
+
typeof patch.set === 'function');
|
|
11
|
+
if (isDescriptor) {
|
|
12
|
+
const descriptor = patch;
|
|
13
|
+
const originalDescriptor = Object.getOwnPropertyDescriptor(target, key);
|
|
14
|
+
Object.defineProperty(target, key, {
|
|
15
|
+
configurable: true,
|
|
16
|
+
enumerable: originalDescriptor ? originalDescriptor.enumerable : true,
|
|
17
|
+
...descriptor
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
else if (typeof original === 'function' && typeof patch === 'function') {
|
|
21
|
+
target[key] = function (...args) {
|
|
22
|
+
return patch.call(this, original.bind(this), ...args);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
target[key] = patch;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|