Skip to content

Commit d52a0b9

Browse files
authored
Merge pull request #447 from MixinNetwork/bugfix/getAssets
fix getAssets
2 parents 1692bfa + 69fb90f commit d52a0b9

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
module.exports = {
22
transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\](?!(axios|is-retry-allowed)).+\\.(js|jsx)$'],
33
setupFilesAfterEnv: ['<rootDir>/test/crypto.ts'],
4+
setupFiles: ['<rootDir>/setup.jest.js'],
45
};

setup.jest.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { TextDecoder, TextEncoder } from 'util';
2+
global.TextEncoder = TextEncoder;
3+
global.TextDecoder = TextDecoder;

src/webview/client.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,21 @@ export const WebViewApi = () => {
6363
},
6464

6565
getAssets: async (assets: string[], cb: (assets: WebviewAsset[]) => void) => {
66+
const cbf = (str: string) => {
67+
const assets = JSON.parse(str) as WebviewAsset[];
68+
cb(assets);
69+
};
6670
switch (getMixinContext().platform) {
6771
case 'iOS':
6872
if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.getAssets) {
69-
window.assetsCallbackFunction = cb;
73+
window.assetsCallbackFunction = cbf;
7074
await window.webkit.messageHandlers.getAssets.postMessage([assets, 'assetsCallbackFunction']);
7175
}
7276
break;
7377
case 'Android':
7478
case 'Desktop':
7579
if (window.MixinContext && typeof window.MixinContext.getAssets === 'function') {
76-
window.assetsCallbackFunction = cb;
80+
window.assetsCallbackFunction = cbf;
7781
await window.MixinContext.getAssets(assets, 'assetsCallbackFunction');
7882
}
7983
break;

src/webview/type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ declare global {
4949
getTipAddress?: Messengers['getTipAddress'];
5050
tipSign?: Messengers['tipSign'];
5151
};
52-
assetsCallbackFunction?: (res: WebviewAsset[]) => void;
52+
assetsCallbackFunction?: (res: string) => void;
5353
tipAddressCallbackFunction?: (address: string) => void;
5454
tipSignCallbackFunction?: (signature: string) => void;
5555
}

0 commit comments

Comments
 (0)