From 7b48e4e9d248ad90d58c45ade7371a10b1f0713e Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 12 Feb 2019 16:43:01 +0100 Subject: [PATCH] Wait for isReady before js exec (#701) --- packages/app-js/src/index.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/app-js/src/index.tsx b/packages/app-js/src/index.tsx index d827e85246..f425bff289 100644 --- a/packages/app-js/src/index.tsx +++ b/packages/app-js/src/index.tsx @@ -108,7 +108,7 @@ class App extends React.PureComponent { ); } - private runJs = (): void => { + private runJs = async (): Promise => { const { api } = this.props; const { code } = this.state; const { keyring } = uiKeyring; @@ -129,6 +129,8 @@ class App extends React.PureComponent { window: null }; + await this.injected.api.isReady; + // squash into a single line so exceptions (with linenumbers) maps to the same line/origin // as we have in the editor view (TODO: Make the console.error here actually return the full stack) const exec = `(async ({${Object.keys(this.injected).join(',')}}) => { try { ${code} } catch (error) { console.error(error); } })(injected);`;