Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
bb72fc0
move walletConnect logic to evm package
sameoldlab Aug 4, 2024
71f43e2
workbench
sameoldlab Aug 5, 2024
78e8a43
add capsule to evm
sameoldlab Aug 5, 2024
12d2af3
update lockfile
sameoldlab Aug 5, 2024
e869273
shorten chain function names
sameoldlab Aug 5, 2024
a8f14dd
wb: add testing packags
sameoldlab Aug 5, 2024
15d358e
basic multi working
sameoldlab Aug 5, 2024
cb83be4
add changeset
sameoldlab Aug 5, 2024
f54c80b
wb: use official wagmi/connectors
sameoldlab Aug 5, 2024
e537fa4
fuel: update packages
sameoldlab Aug 5, 2024
9c7f464
mapped connectors to namespaces
sameoldlab Aug 6, 2024
ec508e6
upgrade to svelte 5
sameoldlab Aug 6, 2024
379413b
update stores and export
sameoldlab Aug 7, 2024
e34037a
mv index.ts -> createFractl.svelte.ts
sameoldlab Aug 7, 2024
5eaee84
add index.ts
sameoldlab Aug 7, 2024
481a117
debug page
sameoldlab Aug 7, 2024
0083b54
types: move connect function inside connector.fractl
sameoldlab Aug 7, 2024
7682e38
starknet: update types
sameoldlab Aug 7, 2024
1207ada
remove unused promise
sameoldlab Aug 7, 2024
42ee02c
rm ConnectModal declaration file
sameoldlab Aug 7, 2024
529816d
pass state as rune, fixed derived conditionals
sameoldlab Aug 7, 2024
fc057f8
Account component functions
sameoldlab Aug 8, 2024
bb3623c
starknet: passthrough error on connect failure
sameoldlab Aug 8, 2024
13e5ccd
add default on close function
sameoldlab Aug 8, 2024
bc479da
setup testing-library
sameoldlab Aug 9, 2024
dce1fe5
start actions
sameoldlab Aug 9, 2024
c24f1ce
convert accountData to work as generic action
sameoldlab Aug 9, 2024
ac5ce3a
initial state functions
sameoldlab Aug 9, 2024
9f7be01
add tests
sameoldlab Aug 10, 2024
3a8fbcd
update tests
sameoldlab Aug 12, 2024
d037de7
move tests file
sameoldlab Aug 12, 2024
caa1720
rewrote createFractl()
sameoldlab Aug 12, 2024
3b4a3dc
rm fsm utils
sameoldlab Aug 12, 2024
aadb778
add test config
sameoldlab Aug 12, 2024
0c7e16a
rm soft link
sameoldlab Aug 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/tough-boats-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@fractl-ui/evm': patch
'@fractl-ui/starknet': patch
'fractl-ui': patch
---

i will find this text and edit it later
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ dist-ssr
*.sln
*.sw?
.vercel
workbench/src/fractl
5 changes: 5 additions & 0 deletions .scripts/mount.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
echo "mount ./packages/ui/src to ./workbench/src/fractl"
echo "$(pwd) should be the root of the repo"

sudo mount --bind ./packages/ui/src ./workbench/src/fractl
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"prepare": "husky install",
"build": "pnpm -F='./packages/*' --parallel build",
"check": "pnpm -r --no-bail --parallel check",
"dev": "pnpm -F wb dev",
"dev:site": "pnpm -F site dev",
"dev:pkg": "pnpm -F='./packages/*' --parallel dev",
"build:site": "pnpm -F site build",
Expand Down Expand Up @@ -37,4 +38,4 @@
"tslib": "^2.6.3",
"typescript": "^5.5.4"
}
}
}
7 changes: 4 additions & 3 deletions packages/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
},
"devDependencies": {
"@fractl-ui/types": "workspace:^",
"vite-plugin-dts": "^3.7.2",
"vite": "^5.3.5"
"@usecapsule/web-sdk": "^1.23.0",
"vite": "^5.3.5",
"vite-plugin-dts": "^3.7.2"
}
}
}
127 changes: 60 additions & 67 deletions packages/evm/src/addConnection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AccountData, AccountDataResponse, Config } from '@fractl-ui/types'
import {
connect,
connect as wagmiConnect,
reconnect,
disconnect,
getAccount,
Expand All @@ -14,106 +14,99 @@ import {
} from '@wagmi/core'
import { formatUnits } from 'viem/utils'
import { map } from 'nanostores'
import { getUri } from './connect.js'

type WagmiConfig = Config<Connector>

/**
* Provides connection details to fractl-modal passed into it's config parameter
*/
export const addEvmConnection = async (
config: wagmiConfig,
{ resolver } = { resolver: 'ENS' }
): Promise<WagmiConfig> => {
export const eip155 = (config: wagmiConfig): WagmiConfig => {
const state = map({
current: config.state.connections.get(config.state.current),
status: config.state.status
})

const accountData = map<AccountData>({
account: null,
balance: null,
nameService: {
name: null,
avatar: null
}
})

config.subscribe(
(state) => state.current,
(current) => state.setKey('current', config.state.connections.get(current))
)
config.subscribe(
(state) => state.status,
(status) => {
updateAccount(status)
state.setKey('status', status)
}
)

async function updateAccount(
status: 'connected' | 'connecting' | 'disconnected' | 'reconnecting'
) {
if (status !== 'connected') {
accountData.setKey('account', null)
accountData.setKey('balance', null)
accountData.setKey('nameService', { name: undefined, avatar: undefined })
return
}

const account = getAccount(config)
accountData.setKey('account', account)
/* Not sure if this is possible */
if (!account.isConnected) throw Error('account is not connected')
const address = account.address!

try {
const _balance = await getBalance(config, { address })
const balance: AccountDataResponse['balance'] = {
symbol: _balance.symbol,
value: formatUnits(_balance.value, _balance.decimals)
type WatchAccountProps = {
address: `0x${string}`
resolver?: string
}
const watchAccount = ({ address, resolver }: WatchAccountProps) => {
resolver = resolver ?? 'ENS'
const account = map<AccountData>({
address,
balance: null,
nameService: {
name: null,
avatar: null
}
accountData.setKey('balance', balance)

let name: GetEnsNameReturnType, avatar: GetEnsAvatarReturnType
})
;(async function () {
try {
const _balance = await getBalance(config, { address })
const balance: AccountDataResponse['balance'] = {
symbol: _balance.symbol,
value: formatUnits(_balance.value, _balance.decimals)
}
account.setKey('balance', balance)

switch (resolver) {
default:
name = await getEnsName(config, {
address,
blockTag: 'finalized'
})

avatar =
name &&
(await getEnsAvatar(config, {
name,
let name: GetEnsNameReturnType, avatar: GetEnsAvatarReturnType
switch (resolver) {
default:
name = await getEnsName(config, {
address,
blockTag: 'finalized'
}))
})

avatar =
name &&
(await getEnsAvatar(config, {
name,
blockTag: 'finalized'
}))
}
account.setKey('nameService', { name, avatar })
console.debug(account.get())
} catch (error) {
console.error('fetch error', error, account.get())
}
})()
return account
}

// accountData.setKey('account', account)
accountData.setKey('nameService', { name, avatar })
console.log(accountData.get())
} catch (error) {
console.log(accountData.get())
console.error('fetch error', error)
}
const connect = (connector: Connector) => async () => {
const { accounts, chainId } = await wagmiConnect(config, { connector })
return { accounts, chainId }
}

return {
namespace: 'eip155',
state: { subscribe: state.subscribe },
accountData: { subscribe: accountData.subscribe },
get connectors() {
return config.connectors
},
connect: async (connector: Connector) => {
const { accounts, chainId } = await connect(config, { connector })
accountData.setKey('account', {
address: accounts?.[0],
addresses: accounts
const conn = config.connectors.map((c) => {
c.fractl = { getUri: {}, connect: {} }

if (c.id === 'walletConnect')
c.fractl.getUri = async (callback: (uri: string) => void) =>
await getUri(c, callback)

c.fractl.connect = connect(c)
return c
})
return { accounts, chainId }
return conn
},
watchAccount,
reconnect: async (connectors: Connector[]) =>
await reconnect(config, { connectors }),
disconnect: async (connector?: Connector) =>
Expand Down
12 changes: 12 additions & 0 deletions packages/evm/src/connect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {EthereumProvider} from '@walletconnect/ethereum-provider'
import type { Connector } from '@wagmi/core'
type Provider = Awaited<ReturnType<(typeof EthereumProvider)['init']>>

export const getUri = async (connector: Connector, callback: (uri: string)=>void) => {
const provider = await connector.getProvider() as Provider
if (!provider) return
console.log(provider)
provider.on('display_uri', callback)
provider.connect()
}

2 changes: 1 addition & 1 deletion packages/evm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export { mock } from './connectors/mock.js'
/* Could just delete this folder with new project structure... */
export { walletConnect } from './connectors/walletConnect.js'

export { addEvmConnection } from './addConnection.js'
export { eip155 } from './addConnection.js'
6 changes: 4 additions & 2 deletions packages/evm/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ export default defineConfig({
},
rollupOptions: {
treeshake: true,
external: ['@walletconnect/ethereum-provider', '@wagmi/core', 'viem'],
external: ['@walletconnect/ethereum-provider', '@wagmi/core', 'viem', '@usecapsule/web-sdk'],
output: {
globals: {
'@wagmi/core': 'wagmi',
'@walletconnect/ethereum-provider': 'walletconnect-ethereum-provider'
'@walletconnect/ethereum-provider': 'walletconnect-ethereum-provider',
'@usecapsule/web-sdk': 'usecapsule-web-sdk',
viem: 'viem'
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions packages/fuel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
},
"dependencies": {
"@fuel-wallet/sdk": "^0.15.2",
"nanostores": "^0.9.5",
"fuels": "^0.74.0"
"fuels": "^0.74.0",
"nanostores": "^0.9.5"
},
"devDependencies": {
"@fractl-ui/types": "workspace:^",
"@fuel-wallet/playwright-utils": "^0.15.2",
"playwright": "^1.41.2",
"vite-plugin-dts": "^3.7.2",
"vite": "^5.3.5"
"playwright": "^1.45.3",
"vite": "^5.3.5",
"vite-plugin-dts": "^3.9.1"
}
}
3 changes: 2 additions & 1 deletion packages/fuel/src/addConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type FuelConnectionObj = Config<FuelConnector>
/**
* Provides connection details to fractl-modal passed into it's config parameter
*/
export const addFuel = async (
export const fuel = async (
{ config, providerUrl, autoconnect }: FuelConnectionProps = {
autoconnect: true,
providerUrl: 'https://beta-5.fuel.network/graphql'
Expand Down Expand Up @@ -114,6 +114,7 @@ export const addFuel = async (
}

return {
namespace: 'fuel',
state: { subscribe: state.subscribe },
accountData: { subscribe: accountData.subscribe },
get connectors() {
Expand Down
2 changes: 1 addition & 1 deletion packages/fuel/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { addFuel } from './addConnection.js'
export { fuel } from './addConnection.js'
Loading