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 1.1.3 #57

Merged
merged 26 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
799743b
feat: add starknetkit hook and return connector instead of wallets
bluecco Dec 7, 2023
328e015
chore: refactor useStarknetkitConnectors params
bluecco Dec 12, 2023
662d7d9
Merge branch 'develop' into BLO-1891
bluecco Dec 12, 2023
1e5cdc6
chore: refactor useStarknetkitConnector
bluecco Dec 12, 2023
8bf4047
Merge branch 'develop' into BLO-1891
bluecco Dec 13, 2023
37121fb
fix: default to mainnet for argent mobile
bluecco Jan 9, 2024
36ff10f
Merge pull request #56 from argentlabs/fix/argent-mobile-chainId
bluecco Jan 9, 2024
5e1f142
chore(release): 1.0.30 [skip ci]
semantic-release-bot Jan 9, 2024
c5f81f0
fix: implement argent mobile connector isPreauthorized method
bluecco Jan 10, 2024
4cc7157
chore: refactor argent mobile isPreauthorized
bluecco Jan 15, 2024
5186278
chore: refactor argent mobile isPreauthorized
bluecco Jan 15, 2024
67bf972
Merge pull request #58 from argentlabs/fix/argent-mobile-isPreauthorized
bluecco Jan 15, 2024
3874f74
Merge pull request #38 from argentlabs/BLO-1891
bluecco Jan 15, 2024
e88e55f
chore(release): 1.1.0 [skip ci]
semantic-release-bot Jan 15, 2024
21de91f
fix: throw UserRejectedRequestError for mobile connector when user re…
bluecco Jan 17, 2024
e2db8ef
Merge pull request #59 from argentlabs/fix/argent-mobile-connect-reject
bluecco Jan 17, 2024
79c7a1f
chore(release): 1.1.1 [skip ci]
semantic-release-bot Jan 17, 2024
c3a5169
fix: use rpc public urls
bluecco Jan 19, 2024
d0d150f
fix: use rpc public urls for mobile connector
bluecco Jan 19, 2024
e09b41b
Merge pull request #60 from argentlabs/fix/rpc-public-urls
bluecco Jan 19, 2024
e447605
chore(release): 1.1.2 [skip ci]
semantic-release-bot Jan 19, 2024
f7a7c63
fix: manage promise reject when user reject a connection in connect m…
bluecco Jan 20, 2024
5927c00
Merge pull request #62 from argentlabs/fix/reject-exception-connect
bluecco Jan 20, 2024
9209e18
chore(release): 1.1.3 [skip ci]
semantic-release-bot Jan 20, 2024
9956718
chore: update CONTRIBUTING.md
Darlington02 Jan 22, 2024
cdcbf7a
Merge pull request #64 from Darlington02/develop
gergold Jan 23, 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
71 changes: 71 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Starknetkit Contribution Guide

Thank you for investing your time in contributing to Starknetkit!

We love pull requests and this guide aims to provide an overview of the contribution workflow to help us make the contribution process effective for everyone involved.

If you want to contribute but don’t know what to do, take a look at issues labelled `good first issue`.

## Getting started

You can contribute to this repo in many ways:

- Solve open issues
- Report bugs or feature requests
- Add new features such as new connectors
- Improve the documentation

Contributions are made via Issues and Pull Requests (PRs). A few general guidelines for contributions:

- Search for existing Issues and PRs before creating your own.
- If you're running into an error, please give context. Explain what you're trying to do and how to reproduce the error.
- Please use the same formatting in the code repository. You can configure your IDE to do it by using the prettier / linting config files included in each package.
- If applicable, please edit the README.md file to reflect the changes.

### Issues

Issues should be used to report problems, request a new feature, or discuss potential changes before a PR is created.

#### Solve an issue

Scan through our existing issues to find one that interests you.

If a contributor is working on the issue, they will be assigned to the individual. If you find an issue to work on, you are welcome to assign it to yourself and open a PR with a fix for it.

### Pull Requests

#### Pull Request Process

We follow the ["fork-and-pull" Git workflow](https://github.com/susam/gitpr)

1. Fork the repo
2. Clone the project
3. Create a new branch with a descriptive name
4. Commit your changes to the new branch
5. Push changes to your fork
6. Open a PR in our repository and tag one of the maintainers to review your PR

Here are some tips for a high-quality pull request:

- Create a title for the PR that accurately defines the work done.
- Structure the description neatly to make it easy to consume by the readers. For example, you can include bullet points and screenshots instead of having one large paragraph.
- Add the link to the issue if applicable.
- Have a good commit message that summarises the work done.

Once you submit your PR:

- We may ask questions, request additional information or ask for changes to be made before a PR can be merged. Please note that these are to make the PR clear for everyone involved and aims to create a frictionless interaction process.
- As you update your PR and apply changes, mark each conversation resolved.
- Once approved, your PR will be merged.

#### Pull request targets
For the most common pull requests such as bug fixes, feature additions, documentation changes, etc., target the develop branch.

### Other notes
- If you have commit access to the repository and want to make a big change or are unsure about something, make a new branch and open a pull request.
- We’re using Prettier to format code, so don’t worry much about code formatting.
- Don’t commit generated files, like minified JavaScript.
- Don’t change the version number or changelog.

### Need help?
If you want to contribute but have any questions, concerns or doubts, feel free to ping maintainers. Ideally create a pull request with WIP (Work in progress) in its title and ask questions in the pull request description.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "starknetkit",
"version": "1.0.29",
"version": "1.1.3",
"repository": "github:argentlabs/starknetkit",
"private": false,
"browser": {
Expand Down
40 changes: 29 additions & 11 deletions src/connectors/argentMobile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
ConnectorNotConnectedError,
ConnectorNotFoundError,
UserNotConnectedError,
UserRejectedRequestError,
} from "../../errors"
import { resetWalletConnect } from "../../helpers/resetWalletConnect"
import {
Expand All @@ -18,6 +19,7 @@ import {
} from "../connector"
import type { StarknetAdapter } from "./modal/starknet/adapter"
import { removeStarknetLastConnectedWallet } from "../../helpers/lastConnected"
import { getRandomPublicRPCNode } from "../../helpers/publicRcpNodes"

export interface ArgentMobileConnectorOptions {
dappName?: string
Expand All @@ -27,6 +29,7 @@ export interface ArgentMobileConnectorOptions {
url?: string
icons?: string[]
provider?: ProviderInterface
rpcUrl?: string
}

export class ArgentMobileConnector extends Connector {
Expand All @@ -43,6 +46,9 @@ export class ArgentMobileConnector extends Connector {
}

async ready(): Promise<boolean> {
// check if session is valid and retrieve the wallet
// if no sessions, it will show the login modal
await this.ensureWallet()
if (!this._wallet) {
return false
}
Expand Down Expand Up @@ -145,19 +151,33 @@ export class ArgentMobileConnector extends Connector {

private async ensureWallet(): Promise<void> {
const { getStarknetWindowObject } = await import("./modal")
const { chainId, projectId, dappName, description, url, icons } =
this._options
const {
chainId,
projectId,
dappName,
description,
url,
icons,
provider,
rpcUrl,
} = this._options

const publicRPCNode = getRandomPublicRPCNode()
const providerRpcUrl =
rpcUrl ??
(!chainId || chainId === constants.NetworkName.SN_MAIN
? publicRPCNode.mainnet
: publicRPCNode.testnet)

const options = {
chainId: chainId ?? constants.NetworkName.SN_MAIN,
name: dappName,
projectId: projectId ?? DEFAULT_PROJECT_ID,
description,
url,
icons,
rpcUrl:
chainId === constants.NetworkName.SN_MAIN
? "https://cloud.argent-api.com/v1/starknet/mainnet/rpc/v0.5"
: "https://api.hydrogen.argent47.net/v1/starknet/goerli/rpc/v0.5",
provider,
rpcUrl: providerRpcUrl,
}

if (projectId === DEFAULT_PROJECT_ID) {
Expand All @@ -177,11 +197,9 @@ export class ArgentMobileConnector extends Connector {

const _wallet = await getStarknetWindowObject(options)

const { provider } = this._options
if (provider) {
Object.assign(_wallet, {
provider,
})
// getStarknetWindowObject returns null when the user rejects the connection
if (!_wallet) {
throw new UserRejectedRequestError()
}

this._wallet = _wallet
Expand Down
2 changes: 2 additions & 0 deletions src/connectors/argentMobile/modal/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import {
} from "@walletconnect/utils"

import type { EthereumRpcConfig } from "./starknet/adapter"
import { ProviderInterface } from "starknet"

export interface NamespaceAdapterOptions {
client: SignClient
chainId?: string | number
rpcUrl?: string
provider: ProviderInterface
}

export abstract class NamespaceAdapter {
Expand Down
6 changes: 4 additions & 2 deletions src/connectors/argentMobile/modal/login.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import SignClient from "@walletconnect/sign-client"
import type { SignClientTypes } from "@walletconnect/types"

import { constants } from "starknet"
import { ProviderInterface, constants } from "starknet"

// Using NetworkName as a value.
const Network: typeof constants.NetworkName = constants.NetworkName
Expand All @@ -22,6 +22,7 @@ export interface IArgentLoginOptions {
mobileUrl?: string
modalType?: "overlay" | "window"
walletConnect?: SignClientTypes.Options
provider?: ProviderInterface
}

export const login = async <TAdapter extends NamespaceAdapter>(
Expand All @@ -37,6 +38,7 @@ export const login = async <TAdapter extends NamespaceAdapter>(
url,
icons,
walletConnect,
provider,
}: IArgentLoginOptions,
Adapter: new (options: NamespaceAdapterOptions) => TAdapter,
): Promise<TAdapter | null> => {
Expand All @@ -63,7 +65,7 @@ export const login = async <TAdapter extends NamespaceAdapter>(
}

const client = await SignClient.init(signClientOptions)
const adapter = new Adapter({ client, chainId, rpcUrl })
const adapter = new Adapter({ client, chainId, rpcUrl, provider })

client.on("session_event", (_) => {
// Handle session events, such as "chainChanged", "accountsChanged", etc.
Expand Down
9 changes: 5 additions & 4 deletions src/connectors/argentMobile/modal/starknet/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ export class StarknetAdapter

private walletRpc: IStarknetRpc

constructor({ client, chainId, rpcUrl }: NamespaceAdapterOptions) {
constructor({ client, chainId, rpcUrl, provider }: NamespaceAdapterOptions) {
super()

this.chainId = String(chainId || "SN_GOERLI")
this.chainId = String(chainId ?? constants.NetworkName.SN_MAIN)
this.rpc = {
chains: chainId ? [this.formatChainId(this.chainId)] : [],
methods: this.methods,
Expand All @@ -84,7 +84,7 @@ export class StarknetAdapter

this.remoteSigner = new StarknetRemoteSigner(this.walletRpc)

this.provider = new RpcProvider({ nodeUrl: rpcUrl })
this.provider = provider ? provider : new RpcProvider({ nodeUrl: rpcUrl })
this.account = new StarknetRemoteAccount(
this.provider,
"",
Expand Down Expand Up @@ -127,7 +127,8 @@ export class StarknetAdapter
}

async isPreauthorized(): Promise<boolean> {
throw new Error("Not implemented: .isPreauthorized()")
// check if wc session is valid, if so, return true
return Boolean(this.client.session.getAll().find(this.isValidSession))
}

on: ConnectedStarknetWindowObject["on"] = (event, handleEvent) => {
Expand Down
3 changes: 2 additions & 1 deletion src/connectors/injected/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
UserNotConnectedError,
UserRejectedRequestError,
} from "../../errors"
import { removeStarknetLastConnectedWallet } from "../../helpers/lastConnected"
import {
Connector,
type ConnectorData,
Expand Down Expand Up @@ -153,7 +154,7 @@ export class InjectedConnector extends Connector {

async disconnect(): Promise<void> {
this.ensureWallet()

removeStarknetLastConnectedWallet()
if (!this.available()) {
throw new ConnectorNotFoundError()
}
Expand Down
6 changes: 0 additions & 6 deletions src/connectors/webwallet/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,3 @@ export const DEFAULT_WEBWALLET_ICON = `<svg
fill="currentColor"
/>
</svg>`

export const RPC_NODE_URL_TESTNET =
"https://api.hydrogen.argent47.net/v1/starknet/goerli/rpc/v0.5"

export const RPC_NODE_URL_MAINNET =
"https://cloud.argent-api.com/v1/starknet/mainnet/rpc/v0.5"
13 changes: 7 additions & 6 deletions src/connectors/webwallet/helpers/mapTargetUrlToNodeUrl.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import { RPC_NODE_URL_MAINNET, RPC_NODE_URL_TESTNET } from "../constants"
import { getRandomPublicRPCNode } from "../../../helpers/publicRcpNodes"

export function mapTargetUrlToNodeUrl(target: string): string {
const publicRPCNode = getRandomPublicRPCNode()
try {
const { origin } = new URL(target)
if (origin.includes("localhost") || origin.includes("127.0.0.1")) {
return RPC_NODE_URL_TESTNET
return publicRPCNode.testnet
}
if (origin.includes("hydrogen")) {
return RPC_NODE_URL_TESTNET
return publicRPCNode.testnet
}
if (origin.includes("staging")) {
return RPC_NODE_URL_MAINNET
return publicRPCNode.mainnet
}
if (origin.includes("argent.xyz")) {
return RPC_NODE_URL_MAINNET
return publicRPCNode.mainnet
}
} catch (e) {
console.warn(
"Could not determine rpc nodeUrl from target URL, defaulting to mainnet",
)
}
return RPC_NODE_URL_MAINNET
return publicRPCNode.mainnet
}
2 changes: 2 additions & 0 deletions src/connectors/webwallet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from "../../errors"
import { DEFAULT_WEBWALLET_ICON, DEFAULT_WEBWALLET_URL } from "./constants"
import { getWebWalletStarknetObject } from "./starknetWindowObject/getWebWalletStarknetObject"
import { removeStarknetLastConnectedWallet } from "../../helpers/lastConnected"

let _wallet: StarknetWindowObject | null = null

Expand Down Expand Up @@ -119,6 +120,7 @@ export class WebWalletConnector extends Connector {
}
_wallet = null
this._wallet = _wallet
removeStarknetLastConnectedWallet()
}

async account(): Promise<AccountInterface> {
Expand Down
5 changes: 4 additions & 1 deletion src/helpers/defaultConnectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export const defaultConnectors = ({
webWalletUrl?: string
provider?: ProviderInterface
}): Connector[] => {
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent)
const isSafari =
typeof window !== "undefined"
? /^((?!chrome|android).)*safari/i.test(navigator.userAgent)
: false

const defaultConnectors: Connector[] = []

Expand Down
22 changes: 22 additions & 0 deletions src/helpers/publicRcpNodes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export type PublicRpcNode = {
mainnet: string
testnet: string
}

// Public RPC nodes
export const BLAST_RPC_NODE: PublicRpcNode = {
mainnet: "https://starknet-mainnet.public.blastapi.io",
testnet: "https://starknet-testnet.public.blastapi.io",
} as const

export const LAVA_RPC_NODE: PublicRpcNode = {
mainnet: "https://rpc.starknet.lava.build",
testnet: "https://rpc.starknet-testnet.lava.build",
} as const

export const PUBLIC_RPC_NODES = [BLAST_RPC_NODE, LAVA_RPC_NODE] as const

export function getRandomPublicRPCNode() {
const randomIndex = Math.floor(Math.random() * PUBLIC_RPC_NODES.length)
return PUBLIC_RPC_NODES[randomIndex]
}
23 changes: 23 additions & 0 deletions src/hooks/useStarknetkitConnectModal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { connect } from "../main"
import { ConnectOptions, ModalResult } from "../types/modal"

type UseStarknetkitConnectors = {
starknetkitConnectModal: () => Promise<ModalResult>
}

const useStarknetkitConnectModal = (
options: Omit<ConnectOptions, "argentMobileOptions" | "webWalletUrl">,
): UseStarknetkitConnectors => {
const starknetkitConnectModal = async (): Promise<ModalResult> => {
return await connect({
...options,
resultType: options.resultType ?? "connector",
})
}

return {
starknetkitConnectModal,
}
}

export { useStarknetkitConnectModal }
Loading
Loading