Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release v1.0.21 #24

Merged
merged 36 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9fe7c6c
fix: starknet peer dependency
bluecco Nov 6, 2023
6cf52e2
Merge pull request #21 from argentlabs/fix/starknet-peer-dep
bluecco Nov 6, 2023
50e12ce
chore(release): 1.0.13 [skip ci]
semantic-release-bot Nov 6, 2023
1b55b6e
fix: open webwallet with click
bluecco Nov 7, 2023
185cdb1
fix: update default connectors ordering
bluecco Nov 7, 2023
a56acdb
Merge pull request #22 from argentlabs/BLO-1765
bluecco Nov 8, 2023
e2b46c9
chore(release): 1.0.14 [skip ci]
semantic-release-bot Nov 8, 2023
52fa756
Merge pull request #23 from argentlabs/BLO-1767
bluecco Nov 8, 2023
a3f592c
chore(release): 1.0.15 [skip ci]
semantic-release-bot Nov 8, 2023
7b75a5a
fix: remove console log
bluecco Nov 8, 2023
575ced2
Merge pull request #25 from argentlabs/fix/remove-console-log
bluecco Nov 8, 2023
92b0c8a
chore(release): 1.0.16 [skip ci]
semantic-release-bot Nov 8, 2023
6e68b0f
fix: update default network for argent mobile
bluecco Nov 9, 2023
facf6f3
Merge pull request #26 from argentlabs/fix/update-default-network-mobil
bluecco Nov 10, 2023
b4091c3
chore(release): 1.0.17 [skip ci]
semantic-release-bot Nov 10, 2023
24b31ed
fix: add ConnectIcons to be inline with starknet-react
dhruvkelawala Nov 10, 2023
849ba2d
fix: improve logic
dhruvkelawala Nov 10, 2023
60bdaa4
Merge pull request #27 from argentlabs/fix/connector-icons
dhruvkelawala Nov 11, 2023
725444b
chore(release): 1.0.18 [skip ci]
semantic-release-bot Nov 11, 2023
ab4b79b
fix: connector connect
dhruvkelawala Nov 11, 2023
324e7ac
fix: double bigint
dhruvkelawala Nov 11, 2023
4963d0f
Merge pull request #28 from argentlabs/fix/connector-connect
dhruvkelawala Nov 11, 2023
0bbd516
chore(release): 1.0.19 [skip ci]
semantic-release-bot Nov 11, 2023
7f43d59
fix: throw account
dhruvkelawala Nov 12, 2023
0770d3f
fix: minor errors
dhruvkelawala Nov 12, 2023
536ee1a
fix: icons
dhruvkelawala Nov 12, 2023
4d1a81b
fix: await ensureWallet
dhruvkelawala Nov 12, 2023
a8ca44e
fix: argent mobile and webwallet chainId method remove ensureWallet
bluecco Nov 13, 2023
504a6a7
chore: update ensureWallet method for injected to be compliant with s…
bluecco Nov 13, 2023
c5c424a
Merge pull request #29 from argentlabs/chore/housekeeping
bluecco Nov 13, 2023
90245ac
chore(release): 1.0.20 [skip ci]
semantic-release-bot Nov 13, 2023
3bf3b17
fix: expose check for argent mobile inApp browser
bluecco Nov 14, 2023
4812868
fix: update logic to show argent mobile when safari popup block is ac…
bluecco Nov 21, 2023
8995456
Merge pull request #30 from argentlabs/fix/check-inapp-browser
bluecco Nov 21, 2023
a463078
Merge pull request #32 from argentlabs/fix/argent-mobile-open
bluecco Nov 21, 2023
7e0d7ed
chore(release): 1.0.21 [skip ci]
semantic-release-bot Nov 21, 2023
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "starknetkit",
"version": "1.0.12",
"version": "1.0.21",
"repository": "github:argentlabs/starknetkit",
"private": false,
"browser": {
Expand Down Expand Up @@ -104,7 +104,7 @@
"zod": "^3.20.6"
},
"peerDependencies": {
"starknet": "5.18.0"
"starknet": "^5.18.0"
},
"gitHead": "b16688a8638cc138938e74e1a39d004760165d75"
}
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions src/connectors/argentMobile/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
export const DEFAULT_PROJECT_ID = "f2e613881f7a0e811295cdd57999e31b"

export const DEFAULT_ARGENT_MOBILE_ICON = `<svg
width="32"
height="32"
viewBox="0 0 32 32"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<rect width="32" height="32" rx="8" fill="#FF875B" />
<path
d="M18.316 8H13.684C13.5292 8 13.4052 8.1272 13.4018 8.28531C13.3082 12.7296 11.0323 16.9477 7.11513 19.9355C6.99077 20.0303 6.96243 20.2085 7.05335 20.3369L9.76349 24.1654C9.85569 24.2957 10.0353 24.3251 10.1618 24.2294C12.6111 22.3734 14.5812 20.1345 16 17.6529C17.4187 20.1345 19.389 22.3734 21.8383 24.2294C21.9646 24.3251 22.1443 24.2957 22.2366 24.1654L24.9467 20.3369C25.0375 20.2085 25.0092 20.0303 24.885 19.9355C20.9676 16.9477 18.6918 12.7296 18.5983 8.28531C18.5949 8.1272 18.4708 8 18.316 8Z"
fill="white"
/>
</svg>`
13 changes: 13 additions & 0 deletions src/connectors/argentMobile/helpers/inAppBrowser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { StarknetWindowObject } from "get-starknet-core"

export const isInArgentMobileAppBrowser = (): boolean => {
if (!window?.starknet_argentX) {
return false
}

const starknetMobile = window?.starknet_argentX as StarknetWindowObject & {
isInAppBrowser: boolean
}

return starknetMobile?.isInAppBrowser
}
1 change: 1 addition & 0 deletions src/connectors/argentMobile/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./inAppBrowser"
66 changes: 36 additions & 30 deletions src/connectors/argentMobile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import type {
} from "get-starknet-core"
import type { AccountInterface } from "starknet"
import { constants } from "starknet"
import { DEFAULT_PROJECT_ID } from "./constants"
import { DEFAULT_ARGENT_MOBILE_ICON, DEFAULT_PROJECT_ID } from "./constants"
import {
ConnectorNotConnectedError,
ConnectorNotFoundError,
UserNotConnectedError,
} from "../../errors"
import { resetWalletConnect } from "../../helpers/resetWalletConnect"
import { Connector } from "../connector"
import {
Connector,
type ConnectorData,
type ConnectorIcons,
} from "../connector"
import type { StarknetAdapter } from "./modal/starknet/adapter"
import { removeStarknetLastConnectedWallet } from "../../helpers/lastConnected"

Expand Down Expand Up @@ -49,23 +53,14 @@ export class ArgentMobileConnector extends Connector {
}

get name(): string {
return "Argent Mobile"
return "Argent (mobile)"
}

get icon(): string {
return `<svg
width="32"
height="32"
viewBox="0 0 32 32"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<rect width="32" height="32" rx="8" fill="#FF875B" />
<path
d="M18.316 8H13.684C13.5292 8 13.4052 8.1272 13.4018 8.28531C13.3082 12.7296 11.0323 16.9477 7.11513 19.9355C6.99077 20.0303 6.96243 20.2085 7.05335 20.3369L9.76349 24.1654C9.85569 24.2957 10.0353 24.3251 10.1618 24.2294C12.6111 22.3734 14.5812 20.1345 16 17.6529C17.4187 20.1345 19.389 22.3734 21.8383 24.2294C21.9646 24.3251 22.1443 24.2957 22.2366 24.1654L24.9467 20.3369C25.0375 20.2085 25.0092 20.0303 24.885 19.9355C20.9676 16.9477 18.6918 12.7296 18.5983 8.28531C18.5949 8.1272 18.4708 8 18.316 8Z"
fill="white"
/>
</svg>`
get icon(): ConnectorIcons {
return {
dark: DEFAULT_ARGENT_MOBILE_ICON,
light: DEFAULT_ARGENT_MOBILE_ICON,
}
}

get wallet(): StarknetWindowObject {
Expand All @@ -75,14 +70,21 @@ export class ArgentMobileConnector extends Connector {
return this._wallet
}

async connect(): Promise<AccountInterface> {
async connect(): Promise<ConnectorData> {
await this.ensureWallet()

if (!this._wallet) {
throw new ConnectorNotFoundError()
}

return this._wallet.account as unknown as AccountInterface
const account = this._wallet.account as unknown as AccountInterface

const chainId = await this.chainId()

return {
account: account.address,
chainId,
}
}

async disconnect(): Promise<void> {
Expand All @@ -101,22 +103,24 @@ export class ArgentMobileConnector extends Connector {
this._wallet = null
}

async account(): Promise<AccountInterface | null> {
/*
Don't throw an exception if the wallet is not connected.
This is needed because when argentMobile and webwallet connectors are used together with starknet-react,
it would always try to retrieve the account since the connectors are always available (and throw an exception since the value is null)

https://github.com/apibara/starknet-react/blob/226e4cb1d8e9b478dc57d45a98a59a57733572bb/packages/core/src/hooks/useAccount.ts#L92

*/
async account(): Promise<AccountInterface> {
if (!this._wallet || !this._wallet.account) {
return null
throw new ConnectorNotConnectedError()
}

return this._wallet.account as AccountInterface
}

async chainId(): Promise<bigint> {
if (!this._wallet || !this.wallet.account || !this._wallet.provider) {
throw new ConnectorNotConnectedError()
}

const chainIdHex = await this._wallet.provider.getChainId()
const chainId = BigInt(chainIdHex)
return chainId
}

// needed, methods required by starknet-react. Otherwise an exception is throwd
async initEventListener(accountChangeCb: AccountChangeEventHandler) {
if (!this._wallet) {
Expand All @@ -141,7 +145,7 @@ export class ArgentMobileConnector extends Connector {
const { getStarknetWindowObject } = await import("./modal")
const { chainId, projectId, dappName, description, url } = this._options
const options = {
chainId: chainId ?? "SN_GOERLI",
chainId: chainId ?? constants.NetworkName.SN_MAIN,
name: dappName,
projectId: projectId ?? DEFAULT_PROJECT_ID,
description,
Expand Down Expand Up @@ -180,3 +184,5 @@ export class ArgentMobileConnector extends Connector {
})
}
}

export { isInArgentMobileAppBrowser } from "./helpers"
2 changes: 1 addition & 1 deletion src/connectors/argentMobile/modal/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export abstract class NamespaceAdapter {
}: SessionTypes.Struct) => {
const chain = this.formatChainId(this.chainId)
if (requiredNamespaces) {
return !!requiredNamespaces[this.namespace]?.chains.includes(chain)
return !!requiredNamespaces[this.namespace]?.chains?.includes(chain)
}
return !!namespaces?.[this.namespace]?.accounts.some((account) =>
account.startsWith(chain),
Expand Down
8 changes: 5 additions & 3 deletions src/connectors/argentMobile/modal/argentModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ class ArgentModal {
}

if (device === "android" || device === "ios") {
const toMobileApp = document.createElement("a")
toMobileApp.setAttribute("href", urls[device])
toMobileApp.setAttribute("target", "_blank")
const toMobileApp = document.createElement("button")
toMobileApp.style.display = "none"
toMobileApp.addEventListener("click", () => {
window.location.href = urls[device]
})
toMobileApp.click()

return
Expand Down
3 changes: 2 additions & 1 deletion src/connectors/argentMobile/modal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export type { StarknetWindowObject, IArgentLoginOptions }

export const getStarknetWindowObject = async (
options: IArgentLoginOptions,
): Promise<ConnectedStarknetWindowObject> => login(options, StarknetAdapter)
): Promise<ConnectedStarknetWindowObject | null> =>
login(options, StarknetAdapter)
10 changes: 9 additions & 1 deletion src/connectors/argentMobile/modal/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ export const login = async <TAdapter extends NamespaceAdapter>(
walletConnect,
}: IArgentLoginOptions,
Adapter: new (options: NamespaceAdapterOptions) => TAdapter,
): Promise<TAdapter> => {
): Promise<TAdapter | null> => {
if (!bridgeUrl) {
throw new Error("bridgeUrl is required")
}

if (!mobileUrl) {
throw new Error("mobileUrl is required")
}
argentModal.bridgeUrl = bridgeUrl
argentModal.mobileUrl = mobileUrl
argentModal.type = modalType
Expand Down Expand Up @@ -101,6 +108,7 @@ export const login = async <TAdapter extends NamespaceAdapter>(
} catch (error) {
console.error("@argent/login::error")
argentModal.closeModal()
return null
}
}

Expand Down
38 changes: 25 additions & 13 deletions src/connectors/connector.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import EventEmitter from "eventemitter3"

import type { StarknetWindowObject } from "get-starknet-core"
import type { AccountInterface } from "starknet"
import { AccountInterface } from "starknet"

/** Connector icons, as base64 encoded svg. */
export type ConnectorIcons = {
/** Dark-mode icon. */
dark?: string
/** Light-mode icon. */
light?: string
}

/** Connector data. */
export type ConnectorData = {
Expand All @@ -20,22 +27,27 @@ export interface ConnectorEvents {
/** Emitted when connection is lost. */
disconnect(): void
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any

export abstract class Connector extends EventEmitter<ConnectorEvents> {
/** Unique connector id. */
abstract get id(): string
/** Connector name. */
abstract get name(): string
/** Connector icons. */
abstract get icon(): ConnectorIcons

/** Whether connector is available for use */
abstract available(): boolean

/** Whether connector is already authorized */
abstract ready?(): Promise<boolean>
abstract connect(): Promise<AccountInterface>
abstract ready(): Promise<boolean>
/** Connect wallet. */
abstract connect(): Promise<ConnectorData>
/** Disconnect wallet. */
abstract disconnect(): Promise<void>
abstract account(): Promise<AccountInterface | null>
/** Unique connector id */
abstract get id(): string
/** Connector name */
abstract get name(): string
/** Connector icon */
abstract get icon(): string
/** Get current account. */
abstract account(): Promise<AccountInterface>
/** Get current chain id. */
abstract chainId(): Promise<bigint>
/** Connector StarknetWindowObject */
abstract get wallet(): StarknetWindowObject
}
5 changes: 5 additions & 0 deletions src/connectors/injected/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export const ARGENT_X_ICON = `data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZpZXdCb3g9IjAgMCAzMiAzMiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHJlY3Qgd2lkdGg9IjMyIiBoZWlnaHQ9IjMyIiByeD0iOCIgZmlsbD0iYmxhY2siLz4KPHBhdGggZD0iTTE4LjQwMTggNy41NTU1NkgxMy41OTgyQzEzLjQzNzcgNy41NTU1NiAxMy4zMDkxIDcuNjg3NDcgMTMuMzA1NiA3Ljg1MTQzQzEzLjIwODUgMTIuNDYwMyAxMC44NDg0IDE2LjgzNDcgNi43ODYwOCAxOS45MzMxQzYuNjU3MTEgMjAuMDMxNCA2LjYyNzczIDIwLjIxNjIgNi43MjIwMiAyMC4zNDkzTDkuNTMyNTMgMjQuMzE5NkM5LjYyODE1IDI0LjQ1NDggOS44MTQ0N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iA4LjU5NDA0IDI1LjYzOTMgOC45MTQwMkwyNS4xNjIxIDEwLjQ4ODVDMjUuMDk2MSAxMC43MDY1IDI0Ljc5MyAxMC43MDg4IDI0LjcyMzYgMTAuNDkyWiIgZmlsbD0id2hpdGUiLz4KPC9zdmc+Cg==`

// Icons used when the injected wallet is not found and no icon is provided.
// question-mark-circle from heroicons with color changed to black/white.
export const WALLET_NOT_FOUND_ICON_LIGHT = `data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9Im5vbmUiIHZpZXdCb3g9IjAgMCAyNCAyNCIgc3Ryb2tlLXdpZHRoPSIxLjUiIHN0cm9rZT0iYmxhY2siPgogIDxwYXRoIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgZD0iTTkuODc5IDcuNTE5YzEuMTcxLTEuMDI1IDMuMDcxLTEuMDI1IDQuMjQyIDAgMS4xNzIgMS4wMjUgMS4xNzIgMi42ODcgMCAzLjcxMi0uMjAzLjE3OS0uNDMuMzI2LS42Ny40NDItLjc0NS4zNjEtMS40NS45OTktMS40NSAxLjgyN3YuNzVNMjEgMTJhOSA5IDAgMTEtMTggMCA5IDkgMCAwMTE4IDB6bS05IDUuMjVoLjAwOHYuMDA4SDEydi0uMDA4eiIgLz4KPC9zdmc+`
export const WALLET_NOT_FOUND_ICON_DARK = `data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9Im5vbmUiIHZpZXdCb3g9IjAgMCAyNCAyNCIgc3Ryb2tlLXdpZHRoPSIxLjUiIHN0cm9rZT0id2hpdGUiPgogIDxwYXRoIHN0cm9rZS1saW5lY2FwPSJyb3VuZCIgc3Ryb2tlLWxpbmVqb2luPSJyb3VuZCIgZD0iTTkuODc5IDcuNTE5YzEuMTcxLTEuMDI1IDMuMDcxLTEuMDI1IDQuMj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