From f9d64393c983db4b467dfaf52dabfa25adada491 Mon Sep 17 00:00:00 2001 From: bluecco Date: Mon, 9 Oct 2023 10:14:34 +0200 Subject: [PATCH 01/10] fix: add wallet connect log if projectId is the same as default --- src/connectors/argentMobile/index.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/connectors/argentMobile/index.ts b/src/connectors/argentMobile/index.ts index 395e78c..6759a8d 100644 --- a/src/connectors/argentMobile/index.ts +++ b/src/connectors/argentMobile/index.ts @@ -145,6 +145,21 @@ export class ArgentMobileConnector extends Connector { url, } + if (projectId === DEFAULT_PROJECT_ID) { + console.log("========= NOTICE =========") + console.log( + "While your application will continue to function, we highly recommended", + ) + console.log("signing up for your own API keys.") + console.log( + "Go to WalletConnect Cloud (https://cloud.walletconnect.com) and create a new account.", + ) + console.log( + "Once your account is created, create a new project and collect the Project ID", + ) + console.log("==========================") + } + const _wallet = await getStarknetWindowObject(options) this._wallet = _wallet } From e9591f4bc8cb07f54cabcff9ffb7c3c5ff58636c Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 9 Oct 2023 08:17:25 +0000 Subject: [PATCH 02/10] chore(release): 1.0.4 [skip ci] ## [1.0.4](https://github.com/argentlabs/starknetkit/compare/v1.0.3...v1.0.4) (2023-10-09) ### Bug Fixes * add wallet connect log if projectId is the same as default ([f9d6439](https://github.com/argentlabs/starknetkit/commit/f9d64393c983db4b467dfaf52dabfa25adada491)) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 26feba4..e4dc8db 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "starknetkit", - "version": "1.0.3", + "version": "1.0.4", "repository": "github:argentlabs/starknetkit", "private": false, "browser": { From 85c5fe827d3d4ca0517a35c5d63943fa769397ca Mon Sep 17 00:00:00 2001 From: bluecco Date: Mon, 9 Oct 2023 18:40:35 +0200 Subject: [PATCH 03/10] fix: use localStorage to retrieve the last connected wallet instead of get-starknet-core --- src/connectors/argentMobile/index.ts | 2 ++ src/connectors/injected/index.ts | 2 ++ src/connectors/webwallet/index.ts | 2 ++ src/helpers/lastConnected.ts | 7 +++++++ src/main.ts | 12 +++++++----- 5 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 src/helpers/lastConnected.ts diff --git a/src/connectors/argentMobile/index.ts b/src/connectors/argentMobile/index.ts index 6759a8d..699525f 100644 --- a/src/connectors/argentMobile/index.ts +++ b/src/connectors/argentMobile/index.ts @@ -12,6 +12,7 @@ import { } from "../../errors" import { resetWalletConnect } from "../../helpers/resetWalletConnect" import { Connector } from "../connector" +import { setStarknetLastConnectedWallet } from "../../helpers/lastConnected" export interface ArgentMobileConnectorOptions { dappName?: string @@ -81,6 +82,7 @@ export class ArgentMobileConnector extends Connector { throw new ConnectorNotFoundError() } + setStarknetLastConnectedWallet(this._wallet.id) return this._wallet.account as unknown as AccountInterface } diff --git a/src/connectors/injected/index.ts b/src/connectors/injected/index.ts index 36a9921..cc9d544 100644 --- a/src/connectors/injected/index.ts +++ b/src/connectors/injected/index.ts @@ -11,6 +11,7 @@ import { UserRejectedRequestError, } from "../../errors" import { Connector } from "../connector" +import { setStarknetLastConnectedWallet } from "../../helpers/lastConnected" /** Injected connector options. */ export interface InjectedConnectorOptions { @@ -50,6 +51,7 @@ export class InjectedConnector extends Connector { try { await this._wallet.enable({ starknetVersion: "v5" }) + setStarknetLastConnectedWallet(this._wallet.id) } catch { // NOTE: Argent v3.0.0 swallows the `.enable` call on reject, so this won't get hit. throw new UserRejectedRequestError() diff --git a/src/connectors/webwallet/index.ts b/src/connectors/webwallet/index.ts index 17d5b63..08a7903 100644 --- a/src/connectors/webwallet/index.ts +++ b/src/connectors/webwallet/index.ts @@ -13,6 +13,7 @@ import { UserRejectedRequestError, } from "../../errors" import { getWebWalletStarknetObject } from "./starknetWindowObject/getWebWalletStarknetObject" +import { setStarknetLastConnectedWallet } from "../../helpers/lastConnected" const DEFAULT_WEBWALLET_URL = "https://web.argent.xyz" @@ -97,6 +98,7 @@ export class WebWalletConnector extends Connector { try { await this._wallet.enable({ starknetVersion: "v4" }) + setStarknetLastConnectedWallet(this._wallet.id) } catch { // NOTE: Argent v3.0.0 swallows the `.enable` call on reject, so this won't get hit. throw new UserRejectedRequestError() diff --git a/src/helpers/lastConnected.ts b/src/helpers/lastConnected.ts new file mode 100644 index 0000000..aa34de6 --- /dev/null +++ b/src/helpers/lastConnected.ts @@ -0,0 +1,7 @@ +export const setStarknetLastConnectedWallet = (id: string) => { + localStorage.setItem("starknetLastConnectedWallet", id) +} + +export const removeStarknetLastConnectedWallet = () => { + localStorage.removeItem("starknetLastConnectedWallet") +} diff --git a/src/main.ts b/src/main.ts index 118f185..1db14a1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,6 +9,7 @@ import { mapModalWallets } from "./helpers/mapModalWallets" import { resetWalletConnect } from "./helpers/resetWalletConnect" import Modal from "./modal/Modal.svelte" import type { ConnectOptions, ModalWallet } from "./types/modal" +import { removeStarknetLastConnectedWallet } from "./helpers/lastConnected" export const connect = async ({ modalMode = "canAsk", @@ -28,9 +29,9 @@ export const connect = async ({ }) : connectors - const lastWallet = await sn.getLastConnectedWallet() + const lastWalletId = localStorage.getItem("starknetLastConnectedWallet") if (modalMode === "neverAsk") { - const connector = availableConnectors.find((c) => c.id === lastWallet?.id) + const connector = availableConnectors.find((c) => c.id === lastWalletId) await connector?.connect() return connector?.wallet || null } @@ -38,19 +39,19 @@ export const connect = async ({ const installedWallets = await sn.getAvailableWallets(restOptions) // we return/display wallet options once per first-dapp (ever) connect - if (modalMode === "canAsk" && lastWallet) { + if (modalMode === "canAsk" && lastWalletId) { const preAuthorizedWallets = await sn.getPreAuthorizedWallets({ ...restOptions, }) const wallet = - preAuthorizedWallets.find((w) => w.id === lastWallet?.id) ?? + preAuthorizedWallets.find((w) => w.id === lastWalletId) ?? installedWallets.length === 1 ? installedWallets[0] : undefined if (wallet) { - const connector = availableConnectors.find((c) => c.id === lastWallet?.id) + const connector = availableConnectors.find((c) => c.id === lastWalletId) await connector?.connect() return wallet } // otherwise fallback to modal @@ -84,5 +85,6 @@ export const connect = async ({ export function disconnect(options: DisconnectOptions = {}): Promise { resetWalletConnect() + removeStarknetLastConnectedWallet() return sn.disconnect(options) } From ced908c1724b88a43f81fa8b5003fa177a99fcc8 Mon Sep 17 00:00:00 2001 From: bluecco Date: Mon, 9 Oct 2023 18:40:56 +0200 Subject: [PATCH 04/10] chore: fix argent mobile id in StarknetAdapter --- src/connectors/argentMobile/modal/starknet/adapter.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/connectors/argentMobile/modal/starknet/adapter.ts b/src/connectors/argentMobile/modal/starknet/adapter.ts index 39366e0..8c4152a 100644 --- a/src/connectors/argentMobile/modal/starknet/adapter.ts +++ b/src/connectors/argentMobile/modal/starknet/adapter.ts @@ -36,8 +36,8 @@ export class StarknetAdapter extends NamespaceAdapter implements ConnectedStarknetWindowObject { - id = "starknetkit" - name = "Starknet Kit" + id = "argentMobile" + name = "Argent Mobile" version = "0.1.0" icon = "" provider: ProviderInterface From 751ec251d109403057aef4cb8e686cf621fd72d3 Mon Sep 17 00:00:00 2001 From: bluecco Date: Tue, 10 Oct 2023 10:12:29 +0200 Subject: [PATCH 05/10] chore: refactor setStarknetLastConnectedWallet --- src/connectors/argentMobile/index.ts | 2 -- src/connectors/injected/index.ts | 2 -- src/connectors/webwallet/index.ts | 3 +-- src/main.ts | 6 +++++- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/connectors/argentMobile/index.ts b/src/connectors/argentMobile/index.ts index 699525f..6759a8d 100644 --- a/src/connectors/argentMobile/index.ts +++ b/src/connectors/argentMobile/index.ts @@ -12,7 +12,6 @@ import { } from "../../errors" import { resetWalletConnect } from "../../helpers/resetWalletConnect" import { Connector } from "../connector" -import { setStarknetLastConnectedWallet } from "../../helpers/lastConnected" export interface ArgentMobileConnectorOptions { dappName?: string @@ -82,7 +81,6 @@ export class ArgentMobileConnector extends Connector { throw new ConnectorNotFoundError() } - setStarknetLastConnectedWallet(this._wallet.id) return this._wallet.account as unknown as AccountInterface } diff --git a/src/connectors/injected/index.ts b/src/connectors/injected/index.ts index cc9d544..36a9921 100644 --- a/src/connectors/injected/index.ts +++ b/src/connectors/injected/index.ts @@ -11,7 +11,6 @@ import { UserRejectedRequestError, } from "../../errors" import { Connector } from "../connector" -import { setStarknetLastConnectedWallet } from "../../helpers/lastConnected" /** Injected connector options. */ export interface InjectedConnectorOptions { @@ -51,7 +50,6 @@ export class InjectedConnector extends Connector { try { await this._wallet.enable({ starknetVersion: "v5" }) - setStarknetLastConnectedWallet(this._wallet.id) } catch { // NOTE: Argent v3.0.0 swallows the `.enable` call on reject, so this won't get hit. throw new UserRejectedRequestError() diff --git a/src/connectors/webwallet/index.ts b/src/connectors/webwallet/index.ts index 08a7903..9f8a66a 100644 --- a/src/connectors/webwallet/index.ts +++ b/src/connectors/webwallet/index.ts @@ -13,7 +13,7 @@ import { UserRejectedRequestError, } from "../../errors" import { getWebWalletStarknetObject } from "./starknetWindowObject/getWebWalletStarknetObject" -import { setStarknetLastConnectedWallet } from "../../helpers/lastConnected" +import {} from "../../helpers/lastConnected" const DEFAULT_WEBWALLET_URL = "https://web.argent.xyz" @@ -98,7 +98,6 @@ export class WebWalletConnector extends Connector { try { await this._wallet.enable({ starknetVersion: "v4" }) - setStarknetLastConnectedWallet(this._wallet.id) } catch { // NOTE: Argent v3.0.0 swallows the `.enable` call on reject, so this won't get hit. throw new UserRejectedRequestError() diff --git a/src/main.ts b/src/main.ts index 1db14a1..28fff6c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,7 +9,10 @@ import { mapModalWallets } from "./helpers/mapModalWallets" import { resetWalletConnect } from "./helpers/resetWalletConnect" import Modal from "./modal/Modal.svelte" import type { ConnectOptions, ModalWallet } from "./types/modal" -import { removeStarknetLastConnectedWallet } from "./helpers/lastConnected" +import { + removeStarknetLastConnectedWallet, + setStarknetLastConnectedWallet, +} from "./helpers/lastConnected" export const connect = async ({ modalMode = "canAsk", @@ -71,6 +74,7 @@ export const connect = async ({ dappName, callback: async (value: StarknetWindowObject | null) => { try { + setStarknetLastConnectedWallet(value.id) resolve(value) } finally { setTimeout(() => modal.$destroy()) From 9a6ad6711dcb6a95f0411b751162904aa9e3309a Mon Sep 17 00:00:00 2001 From: bluecco Date: Tue, 10 Oct 2023 10:29:12 +0200 Subject: [PATCH 06/10] chore: avoid saving webwalletid in localstorage for reconnect purposes --- src/main.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index 28fff6c..bb936a1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -74,7 +74,9 @@ export const connect = async ({ dappName, callback: async (value: StarknetWindowObject | null) => { try { - setStarknetLastConnectedWallet(value.id) + if (value.id !== "argentWebWallet") { + setStarknetLastConnectedWallet(value.id) + } resolve(value) } finally { setTimeout(() => modal.$destroy()) From fd829c747190da67bc35bbab853a91c2a1cfecbb Mon Sep 17 00:00:00 2001 From: bluecco Date: Tue, 10 Oct 2023 12:20:25 +0200 Subject: [PATCH 07/10] fix: add prefix to tailwind css classes to avoid conflicts with dapps --- src/modal/ConnectorButton.svelte | 46 ++++++++++++++++++++++++-------- src/modal/Modal.svelte | 42 ++++++++++++++++++++--------- tailwind.config.cjs | 5 ++-- 3 files changed, 68 insertions(+), 25 deletions(-) diff --git a/src/modal/ConnectorButton.svelte b/src/modal/ConnectorButton.svelte index b3895a5..518cafc 100644 --- a/src/modal/ConnectorButton.svelte +++ b/src/modal/ConnectorButton.svelte @@ -14,11 +14,15 @@ href={wallet.download} target="_blank" rel="noopener noreferrer" - class="rounded-md focus:outline-none focus:ring-2 focus:ring-neutral-200 dark:focus:ring-neutral-700 transition-colors" + class={`starknetkit-rounded-md focus:starknetkit-outline-none focus:starknetkit-ring-2 + focus:starknetkit-ring-neutral-200 dark:focus:starknetkit-ring-neutral-700 starknetkit-transition-colors`} >
  • { cb(null) }} @@ -29,16 +33,26 @@ }} > -

    +

    Install {wallet.name}

    - {wallet.name} + {wallet.name}
  • {:else}
  • { @@ -51,16 +65,22 @@ }} > -
    -

    {wallet.title ?? wallet.name}

    -

    {wallet.subtitle ?? ""}

    +
    +

    + {wallet.title ?? wallet.name} +

    +

    + {wallet.subtitle ?? ""} +

    {#if loadingItem === wallet?.id}
    - Loading... + Loading...
    {:else if isSvg}
    {@html wallet.icon}
    {:else} - {wallet?.name} + {wallet?.name} {/if}
  • {/if} diff --git a/src/modal/Modal.svelte b/src/modal/Modal.svelte index ecf2487..6358e24 100644 --- a/src/modal/Modal.svelte +++ b/src/modal/Modal.svelte @@ -46,7 +46,7 @@ (theme === null && window.matchMedia("(prefers-color-scheme: dark)").matches) ) { - darkModeControlClass = "dark" + darkModeControlClass = "starknetkit-dark" } else { darkModeControlClass = "" } @@ -74,8 +74,8 @@ {#if !isInAppBrowser && !emailOnly}
    cb(null)} on:keyup={(e) => { if (e.key === "Escape") { @@ -86,21 +86,39 @@
    e.stopPropagation()} on:keyup={(e) => { e.stopPropagation() }} > -
    -

    Connect to

    +
    +

    + Connect to +

    {dappName}

    -
      +
        {#each modalWallets as wallet} {/each} @@ -142,7 +160,7 @@ @import url("https://fonts.googleapis.com/css2?family=Barlow:wght@500;600&display=swap"); - * { + .starknetkit-font { font-family: "Barlow", -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; @@ -152,7 +170,7 @@ font-feature-settings: "kern"; } - .l2 { + .starknetkit-l2 { color: #8c8c8c; font-size: 12px; font-weight: 500; @@ -161,7 +179,7 @@ text-align: left; } - p { + .starknetkit-p { margin: 0; } diff --git a/tailwind.config.cjs b/tailwind.config.cjs index 62ff797..92b05b9 100644 --- a/tailwind.config.cjs +++ b/tailwind.config.cjs @@ -2,12 +2,13 @@ module.exports = { content: ["./src/**/*.{svelte,ts}"], darkMode: "class", + prefix: "starknetkit-", theme: { extend: { boxShadow: { "list-item": "0px 2px 12px rgba(0, 0, 0, 0.12)", - "modal": "0px 4px 20px rgba(0, 0, 0, 0.5)" - } + modal: "0px 4px 20px rgba(0, 0, 0, 0.5)", + }, }, }, plugins: [], From 47d86c25917b8c28dd52a1df49832c2fdb98e898 Mon Sep 17 00:00:00 2001 From: bluecco Date: Tue, 10 Oct 2023 12:34:54 +0200 Subject: [PATCH 08/10] chore: remove import --- src/connectors/webwallet/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/connectors/webwallet/index.ts b/src/connectors/webwallet/index.ts index 9f8a66a..17d5b63 100644 --- a/src/connectors/webwallet/index.ts +++ b/src/connectors/webwallet/index.ts @@ -13,7 +13,6 @@ import { UserRejectedRequestError, } from "../../errors" import { getWebWalletStarknetObject } from "./starknetWindowObject/getWebWalletStarknetObject" -import {} from "../../helpers/lastConnected" const DEFAULT_WEBWALLET_URL = "https://web.argent.xyz" From ec79c40dbe617b01669cc4d3392878af6f67e62a Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 10 Oct 2023 10:37:44 +0000 Subject: [PATCH 09/10] chore(release): 1.0.5 [skip ci] ## [1.0.5](https://github.com/argentlabs/starknetkit/compare/v1.0.4...v1.0.5) (2023-10-10) ### Bug Fixes * use localStorage to retrieve the last connected wallet instead of get-starknet-core ([85c5fe8](https://github.com/argentlabs/starknetkit/commit/85c5fe827d3d4ca0517a35c5d63943fa769397ca)) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e4dc8db..bd97561 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "starknetkit", - "version": "1.0.4", + "version": "1.0.5", "repository": "github:argentlabs/starknetkit", "private": false, "browser": { From f65d0333358dd0db7ec2f262166d0ea26ca8aa80 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 10 Oct 2023 11:00:41 +0000 Subject: [PATCH 10/10] chore(release): 1.0.6 [skip ci] ## [1.0.6](https://github.com/argentlabs/starknetkit/compare/v1.0.5...v1.0.6) (2023-10-10) ### Bug Fixes * add prefix to tailwind css classes to avoid conflicts with dapps ([fd829c7](https://github.com/argentlabs/starknetkit/commit/fd829c747190da67bc35bbab853a91c2a1cfecbb)) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bd97561..994a917 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "starknetkit", - "version": "1.0.5", + "version": "1.0.6", "repository": "github:argentlabs/starknetkit", "private": false, "browser": {