From 451d0a45da2145417f6ae51bd45694024f87d190 Mon Sep 17 00:00:00 2001 From: ibro Date: Tue, 7 May 2024 21:21:11 +0100 Subject: [PATCH 1/3] fix starknet type errors --- packages/starknet/src/connections.ts | 43 ++++++++++++++-------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/packages/starknet/src/connections.ts b/packages/starknet/src/connections.ts index 3b44224..4df623b 100644 --- a/packages/starknet/src/connections.ts +++ b/packages/starknet/src/connections.ts @@ -2,8 +2,8 @@ import SN, { type StarknetWindowObject, type ConnectedStarknetWindowObject } from 'get-starknet-core' -import { map } from 'nanostores' -import type { AccountData, Config } from '@fractl-ui/types' +import { map, type MapStore } from 'nanostores' +import type { AccountData, Config, State } from '@fractl-ui/types' import { RpcProvider, defaultProvider, Contract, constants } from 'starknet' import { formatUnits } from './utils/formatUnits.js' import ethABI from './abi/ethABI.js' @@ -12,16 +12,17 @@ const ETH_ADDR = '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7' const DECIMALS = 18 +type SNProvider = { type: string } & StarknetWindowObject /* TODO: Test with metamask snap Integrate Walletconnect */ type StarknetConnectProps = { - starknetVersion?: 'v4' | 'v5' | null + starknetVersion?: 'v4' | 'v5' | undefined /** * Defaults to a list of preauthorized or available wallets */ - connectors: StarknetWindowObject[] + connectors: SNProvider[] /* opt to include install link when no wallet is available */ /** * If `true` reconnects to the first available connected wallet in `connectors` @@ -30,9 +31,8 @@ type StarknetConnectProps = { provider: RpcProvider resolver: 'STARKNET_ID' - clearLastWallet?: boolean | null + clearLastWallet?: boolean | undefined } - export const addStarknetConnection = async ( { starknetVersion, @@ -51,32 +51,30 @@ export const addStarknetConnection = async ( }), resolver: 'STARKNET_ID' } -): Promise => { +): Promise> => { /* Check if user passed in any connectors. If empty get connectors from preauthorized wallets. */ if (connectors.length === 0) { // SN.getDiscoveryWallets().then((res) => connectors.installable.push(...res)) // SN.getPreAuthorizedWallets().then((res) => connectors.push(...res)) - connectors.push(...(await SN.getPreAuthorizedWallets())) - const available = await SN.getAvailableWallets() - connectors.push(...available.filter((a) => !connectors.includes(a))) - - connectors.map((a) => { - if (a.id === 'braavos' || a.id === 'argentX') a.type = 'injected' - return a + const authorized = await SN.getPreAuthorizedWallets() + const available = (await SN.getAvailableWallets()).filter( + (a) => !authorized.includes(a) + ) + const _connectors = [...authorized, ...available].map((a) => { + let type = 'injected' + if (a.id !== 'braavos' && a.id !== 'argentX') type = 'unknown' + return Object.assign(a, { type }) }) + connectors.push(..._connectors) } // SN.getLastConnectedWallet().then((res) => (lastConnected = res)) - const state = map<{ - activeRequest?: StarknetWindowObject | null - current: ConnectedStarknetWindowObject | null - status: 'connecting' | 'disconnected' | 'reconnecting' | 'connected' - }>({ + const state = map({ activeRequest: null, current: null, status: 'disconnected' - }) + }) satisfies MapStore> /* Update status */ state.subscribe(($s) => { @@ -101,14 +99,14 @@ export const addStarknetConnection = async ( } /* Manage Account Data */ - const accountData = map({ + const accountData = map({ account: null, balance: null, nameService: { name: null, avatar: null } - }) + }) satisfies MapStore state.subscribe( ($s, changedKey) => @@ -165,6 +163,7 @@ export const addStarknetConnection = async ( } const connect = async (connector = connectors[0]) => { + if (connector === undefined) return /* Connect and reconnect are effectively the same thing as this does not keep a history of existing connections */ // if (connector?.isConnected) throw Error('already connected') state.setKey('activeRequest', connector) From 0d06b34c269a00bb13628b2046c817997f7e5c99 Mon Sep 17 00:00:00 2001 From: ibro Date: Tue, 7 May 2024 21:32:04 +0100 Subject: [PATCH 2/3] add changeset --- .changeset/funny-phones-rush.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/funny-phones-rush.md diff --git a/.changeset/funny-phones-rush.md b/.changeset/funny-phones-rush.md new file mode 100644 index 0000000..34595a0 --- /dev/null +++ b/.changeset/funny-phones-rush.md @@ -0,0 +1,5 @@ +--- +'@fractl-ui/starknet': patch +--- + +basically the same. types might be nicer, it should build with tsc now From 0ebe6596acf5efdfebdd942aa2f0a52e5a847771 Mon Sep 17 00:00:00 2001 From: ibro Date: Tue, 7 May 2024 22:15:43 +0100 Subject: [PATCH 3/3] switch starknet build to tsc --- packages/starknet/package.json | 7 +++---- packages/starknet/tsconfig.json | 9 +++++++++ packages/tsconfig.json | 16 +++++++--------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/packages/starknet/package.json b/packages/starknet/package.json index 7a26d1f..7472584 100644 --- a/packages/starknet/package.json +++ b/packages/starknet/package.json @@ -21,14 +21,13 @@ ], "exports": { ".": { - "require": "./dist/index.umd.cjs", - "import": "./dist/index.js", - "types": "./dist/index.d.ts" + "types": "./dist/index.d.ts", + "import": "./dist/index.js" } }, "scripts": { "dev": "vite build -w", - "build": "vite build", + "build": "tsc", "prepublishOnly": "pnpm format && pnpm lint", "lint": "eslint .", "format": "prettier --write ." diff --git a/packages/starknet/tsconfig.json b/packages/starknet/tsconfig.json index dfa48c8..c66396f 100644 --- a/packages/starknet/tsconfig.json +++ b/packages/starknet/tsconfig.json @@ -1,4 +1,13 @@ { + "compilerOptions": { + // "target": "ESNext", + "outDir": "dist", + "rootDir": "src", + "declaration": true, + "declarationMap": true, + + "noEmit": false + }, "extends": "../tsconfig.json", "include": ["src"] } diff --git a/packages/tsconfig.json b/packages/tsconfig.json index d84d5c0..bdd4155 100644 --- a/packages/tsconfig.json +++ b/packages/tsconfig.json @@ -1,30 +1,28 @@ { "compilerOptions": { "strict": true, - "esModuleInterop": true, + "esModuleInterop": true, "verbatimModuleSyntax": true, "moduleDetection": "force", "noUncheckedIndexedAccess": true, "resolveJsonModule": true, "skipLibCheck": true, "allowJs": false, - + "target": "ESNext", - + // Run tsc before commits and packaging, but build and _bundle with Vite "moduleResolution": "Bundler", "module": "ESNext", "noEmit": true, - + "isolatedModules": true, - + "useDefineForClassFields": true, "lib": ["ES2020", "DOM", "DOM.Iterable"], - "composite": true, - "declarationMap": true, "noUnusedLocals": true, "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true, - }, + "noFallthroughCasesInSwitch": true + } }