From ed4d08e11b01012ba1512f23a9cc194e9dda9d63 Mon Sep 17 00:00:00 2001 From: ibro Date: Wed, 31 Jul 2024 10:49:49 +0100 Subject: [PATCH 1/6] export connectModal as function --- packages/ui/src/components/index.ts | 18 ++++++++++++++++++ packages/ui/src/index.ts | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/ui/src/components/index.ts b/packages/ui/src/components/index.ts index d2ad327..c3a24f1 100644 --- a/packages/ui/src/components/index.ts +++ b/packages/ui/src/components/index.ts @@ -1,5 +1,23 @@ import ConnectModal from './ConnectModal/ConnectModal.svelte' import AccountModal from './AccountModal.svelte' import FractlModal from './FractlModal.svelte' +import type { Config } from '@fractl-ui/types' +export const create = async (config: Promise>) => { + let _config = await Promise.resolve(config) + + return () => { + const getTarget = () => document.body + + return new Promise((resolve, reject) => { + new ConnectModal({ + target: getTarget(), + props: { + config: _config, + state: _config.state + } + }) + }) + } +} export { ConnectModal, AccountModal, FractlModal } diff --git a/packages/ui/src/index.ts b/packages/ui/src/index.ts index f6913c0..10e92dc 100644 --- a/packages/ui/src/index.ts +++ b/packages/ui/src/index.ts @@ -1,3 +1,3 @@ -export { FractlModal } from './components/index.js' +export { create } from './components/index.js' // export {open connect modal} // export T&C text prop From 301f618e53e4b7578b315d13c3cd9dc6f1c9a22a Mon Sep 17 00:00:00 2001 From: ibro Date: Wed, 31 Jul 2024 10:51:19 +0100 Subject: [PATCH 2/6] update example --- examples/svelte/src/App.svelte | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/svelte/src/App.svelte b/examples/svelte/src/App.svelte index 1c2a6d0..3ac0f8e 100644 --- a/examples/svelte/src/App.svelte +++ b/examples/svelte/src/App.svelte @@ -2,7 +2,7 @@
- +
@@ -58,7 +60,6 @@ - diff --git a/packages/ui/src/components/Common/Modal.svelte b/packages/ui/src/components/Common/Modal.svelte index 212b59c..bbdd9f8 100644 --- a/packages/ui/src/components/Common/Modal.svelte +++ b/packages/ui/src/components/Common/Modal.svelte @@ -103,8 +103,6 @@ {/if} From be533b8e2f0873958cd05770f0baffda48804a3d Mon Sep 17 00:00:00 2001 From: ibro Date: Wed, 31 Jul 2024 12:45:50 +0100 Subject: [PATCH 4/6] return state after connection attempt --- examples/svelte/src/App.svelte | 19 ++++++++-------- .../ConnectModal/ConnectModal.svelte | 22 +++++++++++-------- packages/ui/src/components/index.ts | 17 ++++++++++---- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/examples/svelte/src/App.svelte b/examples/svelte/src/App.svelte index 3ac0f8e..8783c16 100644 --- a/examples/svelte/src/App.svelte +++ b/examples/svelte/src/App.svelte @@ -8,20 +8,23 @@ import { reconnect } from '@wagmi/core' import FractlSvg from './assets/fractl.svg' import './app.css' - // import { addStarknetConnection } frLom '@fractl-ui/starknet' + import { addStarknetConnection } from '@fractl-ui/starknet' onMount(async () => { reconnect($wagmiConfig, { connectors: $wagmiConfig.connectors }) }) - // const config = addStarknetConnection() - const config = addEvmConnection($wagmiConfig) - // const { status } = config.state - const connect = async () => - create(addEvmConnection($wagmiConfig)).then((connect) => connect()) + const stark = addStarknetConnection() + const evm = addEvmConnection($wagmiConfig) + + const connect = async (conf) => create(conf).then((connect) => connect() + .then(res => console.log(res)) + .catch(err => console.error(err)) + )
- + +
@@ -36,8 +39,6 @@

- -
- + @@ -105,7 +109,7 @@ />
- {#if state.status === 'connecting' || state.status === 'reconnecting'} + {#if $state.status === 'connecting' || $state.status === 'reconnecting'}

Requesting Connection

{copyEN(activeRequest.name).connecting[activeRequest.type]} diff --git a/packages/ui/src/components/index.ts b/packages/ui/src/components/index.ts index c3a24f1..a2b0210 100644 --- a/packages/ui/src/components/index.ts +++ b/packages/ui/src/components/index.ts @@ -1,20 +1,29 @@ import ConnectModal from './ConnectModal/ConnectModal.svelte' import AccountModal from './AccountModal.svelte' import FractlModal from './FractlModal.svelte' -import type { Config } from '@fractl-ui/types' +import type { Config, Connector, StateConnected } from '@fractl-ui/types' -export const create = async (config: Promise>) => { +export const create = async (config: Promise>) => { let _config = await Promise.resolve(config) + //TODO: return singleton when modal is dismissed without completing connection return () => { const getTarget = () => document.body return new Promise((resolve, reject) => { - new ConnectModal({ + const modal = new ConnectModal({ target: getTarget(), props: { config: _config, - state: _config.state + state: _config.state, + onConnect: (state: StateConnected) => { + resolve(state) + modal.$destroy() + }, + onConnectFail: (error) => { + reject(error) + modal.$destroy() + } } }) }) From 92b8750c8373004081df797f6b1de7f3f66b3553 Mon Sep 17 00:00:00 2001 From: ibro Date: Wed, 31 Jul 2024 15:26:21 +0100 Subject: [PATCH 5/6] enable svelte imports alows use of connect modal from compiled svelte or direclty importing components --- examples/svelte/src/App.svelte | 17 ++++++++++++----- packages/ui/src/components/AccountModal.svelte | 17 +++++++++-------- .../components/ConnectModal/ConnectModal.svelte | 7 ++++--- packages/ui/src/components/FractlModal.svelte | 7 ++++--- packages/ui/src/index.ts | 6 +++++- 5 files changed, 34 insertions(+), 20 deletions(-) diff --git a/examples/svelte/src/App.svelte b/examples/svelte/src/App.svelte index 8783c16..a8f3d98 100644 --- a/examples/svelte/src/App.svelte +++ b/examples/svelte/src/App.svelte @@ -1,8 +1,6 @@ - -

@@ -38,6 +42,9 @@

+ {#if account} + + {/if}