Skip to content

Commit

Permalink
chore: use starknetkit for wallet connection (#53)
Browse files Browse the repository at this point in the history
Update frontend to use starknetkit for a more robust connect modal.
  • Loading branch information
Darlington02 authored Dec 14, 2023
1 parent 9d30667 commit a977f72
Show file tree
Hide file tree
Showing 7 changed files with 2,582 additions and 1,786 deletions.
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"react-hook-form": "^7.49.0",
"react-router-dom": "^6.11.0",
"starknet": "^5.10.0",
"starknetkit": "^1.0.22",
"ua-parser-js": "^1.0.35",
"zod": "^3.22.4",
"zustand": "^4.3.8"
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/assets/argentmobile.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions frontend/src/assets/webwallet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 10 additions & 6 deletions frontend/src/components/Web3Provider/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { sepolia } from '@starknet-react/chains'
import { argent, braavos, publicProvider, StarknetConfig, starkscan, useInjectedConnectors } from '@starknet-react/core'
import { publicProvider, StarknetConfig, starkscan } from '@starknet-react/core'
import { ArgentMobileConnector } from 'starknetkit/argentMobile'
import { InjectedConnector } from 'starknetkit/injected'
import { WebWalletConnector } from 'starknetkit/webwallet'

// STARKNET

Expand All @@ -8,11 +11,12 @@ interface StarknetProviderProps {
}

export function StarknetProvider({ children }: StarknetProviderProps) {
const { connectors } = useInjectedConnectors({
recommended: [argent(), braavos()],
includeRecommended: 'onlyIfNoConnectors',
order: 'random',
})
const connectors = [
new InjectedConnector({ options: { id: 'argentX', name: 'Argent' } }),
new InjectedConnector({ options: { id: 'braavos', name: 'Braavos' } }),
new WebWalletConnector({ url: 'https://web.argent.xyz' }),
new ArgentMobileConnector(),
]

return (
<StarknetConfig
Expand Down
36 changes: 33 additions & 3 deletions frontend/src/connections/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import { InjectedConnector } from '@starknet-react/core'
import ARGENT_X_ICON from 'src/assets/argent-x.svg'
import ARGENTMOBILE_ICON from 'src/assets/argentmobile.svg'
import BRAAVOS_ICON from 'src/assets/braavos.svg'
import WEBWALLET_ICON from 'src/assets/webwallet.svg'
import { isMobile } from 'src/utils/userAgent'
import { ArgentMobileConnector } from 'starknetkit/argentMobile'
import { InjectedConnector } from 'starknetkit/injected'
import { WebWalletConnector } from 'starknetkit/webwallet'

import { getShouldAdvertiseArgentX, getShouldAdvertiseBraavos } from './utils'

enum ConnectionType {
ARGENT_X = 'ARGENT_X',
BRAAVOS = 'BRAAVOS',
WEBWALLET = 'WEBWALLET',
ARGENTMOBILE = 'ARGENTMOBILE',
}

export interface L2Connection {
getName(): string
connector: InjectedConnector
connector: InjectedConnector | ArgentMobileConnector | WebWalletConnector
type: ConnectionType
getIcon?(): string
shouldDisplay(): boolean
Expand Down Expand Up @@ -61,8 +67,32 @@ const braavosWalletConnection: L2Connection = {
},
}

// WEB WALLET

const webWallet = new WebWalletConnector({ url: 'https://web.argent.xyz' })

const webWalletConnection: L2Connection = {
getName: () => 'Web Wallet',
connector: webWallet,
type: ConnectionType.WEBWALLET,
getIcon: () => WEBWALLET_ICON,
shouldDisplay: () => true,
}

// ARGENT MOBILE

const argentMobile = new ArgentMobileConnector()

const argentMobileConnection: L2Connection = {
getName: () => 'Argent (mobile)',
connector: argentMobile,
type: ConnectionType.ARGENTMOBILE,
getIcon: () => ARGENTMOBILE_ICON,
shouldDisplay: () => true,
}

// GETTERS

export function getL2Connections() {
return [argentXWalletConnection, braavosWalletConnection]
return [argentXWalletConnection, braavosWalletConnection, webWalletConnection, argentMobileConnection]
}
4 changes: 2 additions & 2 deletions frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
"noImplicitThis": true,
"noImplicitReturns": true,
"useUnknownInCatchVariables": false,
"moduleResolution": "node",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"downlevelIteration": true,
"allowSyntheticDefaultImports": true,
"jsx": "preserve",
"module": "commonjs",
"module": "ES2015",
"rootDir": ".",
"baseUrl": ".",
"declaration": true
Expand Down
Loading

0 comments on commit a977f72

Please sign in to comment.