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() + } } }) })