Skip to content

Commit

Permalink
Fix enable wallet issue not recognizing preferred wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
teodorus-nathaniel committed Mar 7, 2024
1 parent 31b1bb3 commit 7f152ea
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 28 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"@subsocial/grill-widget": "^0.0.13",
"@subsocial/resource-discussions": "^0.0.4",
"@subsocial/utils": "0.8.10",
"@talismn/connect-wallets": "^1.2.5",
"@tiptap/extension-highlight": "^2.0.0-beta.33",
"@tiptap/extension-image": "^2.0.0-beta.27",
"@tiptap/extension-link": "^2.0.0-beta.37",
Expand Down
2 changes: 1 addition & 1 deletion src/components/auth/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const recheckStatuses = ['UNAVAILABLE', 'UNAUTHORIZED']

const { appName } = config

export const CURRENT_WALLET = 'CurrentWalletName'
export const CURRENT_WALLET = 'preferred-wallet'

export const getCurrentWallet = (): string => store.get(CURRENT_WALLET)

Expand Down
7 changes: 2 additions & 5 deletions src/components/utils/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const { appBaseUrl, ipfsNodeUrl } = config
import { Skeleton } from 'antd'
import Avatar from 'antd/lib/avatar/avatar'
import { AvatarSize } from 'antd/lib/avatar/SizeContext'
import { InstallUrl, Urls } from '../wallets/types'
import * as offchain from './OffchainUtils'

export function isServerSide(): boolean {
Expand Down Expand Up @@ -300,8 +299,6 @@ export const detectBrowser = () => {
return browser
}

export const getInstallUrl = (instalUrls: InstallUrl) => {
const browser = detectBrowser()

return instalUrls[browser as Urls]
export const getInstallUrl = (instalUrls: string) => {
return instalUrls
}
11 changes: 4 additions & 7 deletions src/components/wallets/supportedWallets/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { Wallet } from '../types'
import { PolkadotjsWallet } from './polkadot-wallet'
import { SubWallet } from './subwallet-wallet'
import { TalismanWallet } from './talisaman-wallet'
import { getWallets, Wallet } from '@talismn/connect-wallets'

export const supportedWallets = [new TalismanWallet(), new SubWallet(), new PolkadotjsWallet()]
export const supportedWallets = getWallets()

export const getWalletBySource = (source: string | unknown): Wallet | undefined => {
return supportedWallets.find(wallet => {
return wallet.extensionName === source
return getWallets().find(wallet => {
return wallet.title === source
})
}

Expand Down
24 changes: 11 additions & 13 deletions src/components/wallets/wallet-list/WalletsList.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DownloadOutlined } from '@ant-design/icons'
import { Wallet } from '@talismn/connect-wallets'
import { Tooltip } from 'antd'
import clsx from 'clsx'
import { useEffect, useMemo, useState } from 'react'
Expand All @@ -11,7 +12,6 @@ import { ButtonLink } from '../../utils/CustomLinks'
import { AvatarOrSkeleton, detectBrowser, getInstallUrl } from '../../utils/index'
import { showWarnMessage } from '../../utils/Message'
import { supportedWallets } from '../supportedWallets/index'
import { Wallet } from '../types'
import styles from './WalletList.module.sass'

export const CURRENT_WALLET = 'preferred-wallet'
Expand Down Expand Up @@ -40,17 +40,15 @@ const WalletList = ({ setCurrentStep }: GetWalletPorps) => {
if (wallet.installed) {
await wallet.enable(appName)

if (wallet.enabled) {
const unsub: any = await wallet.subscribeAccounts(async accounts => {
if (accounts) {
setAccountsToState(accounts, setAccounts)
setCurrentStep(StepsEnum.SelectAccount)
setCurrentWallet(wallet.extensionName)
}
})
const unsub: any = await wallet.subscribeAccounts(async accounts => {
if (accounts) {
setAccountsToState(accounts, setAccounts)
setCurrentStep(StepsEnum.SelectAccount)
setCurrentWallet(wallet.extensionName)
}
})

setUnsubscribe(unsub)
}
setUnsubscribe(unsub)
} else {
showWarnMessage(
`${wallet.title} extension is not installed or refresh the browser if ${wallet.title} is already installed`,
Expand All @@ -69,7 +67,7 @@ const WalletList = ({ setCurrentStep }: GetWalletPorps) => {
}, [supportedWallets])

const wallets = sortedSupportedWallets.map(wallet => {
const { title, logo, installed, installUrls } = wallet
const { title, logo, installed, installUrl } = wallet

const onInstallButtonClick = (e: React.MouseEvent<HTMLElement>) => {
e.stopPropagation()
Expand All @@ -95,7 +93,7 @@ const WalletList = ({ setCurrentStep }: GetWalletPorps) => {
title={`Install ${title} or refresh the browser if ${title} is already installed`}
>
<ButtonLink
href={getInstallUrl(installUrls)}
href={getInstallUrl(installUrl)}
target='_blank'
className={styles.InstallButton}
onClick={onInstallButtonClick}
Expand Down
110 changes: 108 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,19 @@
"@polkadot/util" "^11.1.3"
tslib "^2.5.0"

"@polkadot/[email protected]":
version "9.14.2"
resolved "https://registry.yarnpkg.com/@polkadot/api-augment/-/api-augment-9.14.2.tgz#2c49cdcfdf7057523db1dc8d7b0801391a8a2e69"
integrity sha512-19MmW8AHEcLkdcUIo3LLk0eCQgREWqNSxkUyOeWn7UiNMY1AhDOOwMStUBNCvrIDK6VL6GGc1sY7rkPCLMuKSw==
dependencies:
"@babel/runtime" "^7.20.13"
"@polkadot/api-base" "9.14.2"
"@polkadot/rpc-augment" "9.14.2"
"@polkadot/types" "9.14.2"
"@polkadot/types-augment" "9.14.2"
"@polkadot/types-codec" "9.14.2"
"@polkadot/util" "^10.4.2"

"@polkadot/[email protected]":
version "10.3.4"
resolved "https://registry.yarnpkg.com/@polkadot/api-base/-/api-base-10.3.4.tgz#56a77118eec096f047637a4deb055157a4e159ec"
Expand All @@ -1730,6 +1743,17 @@
rxjs "^7.8.0"
tslib "^2.5.0"

"@polkadot/[email protected]":
version "9.14.2"
resolved "https://registry.yarnpkg.com/@polkadot/api-base/-/api-base-9.14.2.tgz#605b44e3692a125bd8d97eed9cea8af9d0c454e2"
integrity sha512-ky9fmzG1Tnrjr/SBZ0aBB21l0TFr+CIyQenQczoUyVgiuxVaI/2Bp6R2SFrHhG28P+PW2/RcYhn2oIAR2Z2fZQ==
dependencies:
"@babel/runtime" "^7.20.13"
"@polkadot/rpc-core" "9.14.2"
"@polkadot/types" "9.14.2"
"@polkadot/util" "^10.4.2"
rxjs "^7.8.0"

"@polkadot/[email protected]":
version "10.3.4"
resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-10.3.4.tgz#2d460ed17fc42ae221e39d97d1d338474a5362a9"
Expand All @@ -1746,6 +1770,22 @@
rxjs "^7.8.0"
tslib "^2.5.0"

"@polkadot/[email protected]":
version "9.14.2"
resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-9.14.2.tgz#e8fcd4ee3f2b80b9fe34d4dec96169c3bdb4214d"
integrity sha512-yw9OXucmeggmFqBTMgza0uZwhNjPxS7MaT7lSCUIRKckl1GejdV+qMhL3XFxPFeYzXwzFpdPG11zWf+qJlalqw==
dependencies:
"@babel/runtime" "^7.20.13"
"@polkadot/api" "9.14.2"
"@polkadot/api-augment" "9.14.2"
"@polkadot/api-base" "9.14.2"
"@polkadot/rpc-core" "9.14.2"
"@polkadot/types" "9.14.2"
"@polkadot/types-codec" "9.14.2"
"@polkadot/util" "^10.4.2"
"@polkadot/util-crypto" "^10.4.2"
rxjs "^7.8.0"

"@polkadot/[email protected]", "@polkadot/api@latest":
version "10.3.4"
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-10.3.4.tgz#6584b05fcc2d99681d7130cc630c05a9fa5fa797"
Expand All @@ -1769,6 +1809,29 @@
rxjs "^7.8.0"
tslib "^2.5.0"

"@polkadot/[email protected]", "@polkadot/api@^9.3.3":
version "9.14.2"
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-9.14.2.tgz#d5cee02236654c6063d7c4b70c78c290db5aba8d"
integrity sha512-R3eYFj2JgY1zRb+OCYQxNlJXCs2FA+AU4uIEiVcXnVLmR3M55tkRNEwYAZmiFxx0pQmegGgPMc33q7TWGdw24A==
dependencies:
"@babel/runtime" "^7.20.13"
"@polkadot/api-augment" "9.14.2"
"@polkadot/api-base" "9.14.2"
"@polkadot/api-derive" "9.14.2"
"@polkadot/keyring" "^10.4.2"
"@polkadot/rpc-augment" "9.14.2"
"@polkadot/rpc-core" "9.14.2"
"@polkadot/rpc-provider" "9.14.2"
"@polkadot/types" "9.14.2"
"@polkadot/types-augment" "9.14.2"
"@polkadot/types-codec" "9.14.2"
"@polkadot/types-create" "9.14.2"
"@polkadot/types-known" "9.14.2"
"@polkadot/util" "^10.4.2"
"@polkadot/util-crypto" "^10.4.2"
eventemitter3 "^5.0.0"
rxjs "^7.8.0"

"@polkadot/extension-dapp@^0.44.6":
version "0.44.9"
resolved "https://registry.yarnpkg.com/@polkadot/extension-dapp/-/extension-dapp-0.44.9.tgz#0ed8ba7442e36b1dde950c90767a07b13eb2cb81"
Expand All @@ -1779,7 +1842,7 @@
"@polkadot/util" "^10.4.2"
"@polkadot/util-crypto" "^10.4.2"

"@polkadot/extension-inject@^0.44.9":
"@polkadot/extension-inject@^0.44.6", "@polkadot/extension-inject@^0.44.9":
version "0.44.9"
resolved "https://registry.yarnpkg.com/@polkadot/extension-inject/-/extension-inject-0.44.9.tgz#5c4486fabdd799387274a62b0628688e162e206c"
integrity sha512-c23vp0C/8R5C3gdqoH2JRlKcvVjJFl9uM3t6rM/uwDs7GEQr9jrsmIOHGhNoI1/M/xBrCm/KuYNYi0dafdm/Vw==
Expand Down Expand Up @@ -1838,6 +1901,17 @@
"@polkadot/util" "^11.1.3"
tslib "^2.5.0"

"@polkadot/[email protected]":
version "9.14.2"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-augment/-/rpc-augment-9.14.2.tgz#eb70d5511463dab8d995faeb77d4edfe4952fe26"
integrity sha512-mOubRm3qbKZTbP9H01XRrfTk7k5it9WyzaWAg72DJBQBYdgPUUkGSgpPD/Srkk5/5GAQTWVWL1I2UIBKJ4TJjQ==
dependencies:
"@babel/runtime" "^7.20.13"
"@polkadot/rpc-core" "9.14.2"
"@polkadot/types" "9.14.2"
"@polkadot/types-codec" "9.14.2"
"@polkadot/util" "^10.4.2"

"@polkadot/[email protected]":
version "10.3.4"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-10.3.4.tgz#f18d641de4be7857a699ff05cf7c5e5403207e4d"
Expand All @@ -1850,6 +1924,18 @@
rxjs "^7.8.0"
tslib "^2.5.0"

"@polkadot/[email protected]":
version "9.14.2"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-9.14.2.tgz#26d4f00ac7abbf880f8280e9b96235880d35794b"
integrity sha512-krA/mtQ5t9nUQEsEVC1sjkttLuzN6z6gyJxK2IlpMS3S5ncy/R6w4FOpy+Q0H18Dn83JBo0p7ZtY7Y6XkK48Kw==
dependencies:
"@babel/runtime" "^7.20.13"
"@polkadot/rpc-augment" "9.14.2"
"@polkadot/rpc-provider" "9.14.2"
"@polkadot/types" "9.14.2"
"@polkadot/util" "^10.4.2"
rxjs "^7.8.0"

"@polkadot/[email protected]":
version "10.3.4"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-10.3.4.tgz#5accdfbb430c64816bbf3816933bae865064d7a3"
Expand All @@ -1870,7 +1956,7 @@
optionalDependencies:
"@substrate/connect" "0.7.23"

"@polkadot/rpc-provider@^9.14.2":
"@polkadot/rpc-provider@9.14.2", "@polkadot/rpc-provider@^9.14.2":
version "9.14.2"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-9.14.2.tgz#0dea667f3a03bf530f202cba5cd360df19b32e30"
integrity sha512-YTSywjD5PF01V47Ru5tln2LlpUwJiSOdz6rlJXPpMaY53hUp7+xMU01FVAQ1bllSBNisSD1Msv/mYHq84Oai2g==
Expand Down Expand Up @@ -1958,6 +2044,18 @@
"@polkadot/util" "^11.1.3"
tslib "^2.5.0"

"@polkadot/[email protected]":
version "9.14.2"
resolved "https://registry.yarnpkg.com/@polkadot/types-known/-/types-known-9.14.2.tgz#17fe5034a5b907bd006093a687f112b07edadf10"
integrity sha512-iM8WOCgguzJ3TLMqlm4K1gKQEwWm2zxEKT1HZZ1irs/lAbBk9MquDWDvebryiw3XsLB8xgrp3RTIBn2Q4FjB2A==
dependencies:
"@babel/runtime" "^7.20.13"
"@polkadot/networks" "^10.4.2"
"@polkadot/types" "9.14.2"
"@polkadot/types-codec" "9.14.2"
"@polkadot/types-create" "9.14.2"
"@polkadot/util" "^10.4.2"

"@polkadot/[email protected]", "@polkadot/types-support@latest":
version "10.3.4"
resolved "https://registry.yarnpkg.com/@polkadot/types-support/-/types-support-10.3.4.tgz#4a4e28eef85f30510b9b1b1daf79801279bb6fbb"
Expand Down Expand Up @@ -2658,6 +2756,14 @@
resolved "https://registry.yarnpkg.com/@swc/types/-/types-0.1.5.tgz#043b731d4f56a79b4897a3de1af35e75d56bc63a"
integrity sha512-myfUej5naTBWnqOCc/MdVOLVjXUXtIA+NpDrDBKJtLLg2shUjBu3cZmB/85RyitKc55+lUUyl7oRfLOvkr2hsw==

"@talismn/connect-wallets@^1.2.5":
version "1.2.5"
resolved "https://registry.yarnpkg.com/@talismn/connect-wallets/-/connect-wallets-1.2.5.tgz#dde0a4732bd12f4e36203cddbcb65fbf42361d0c"
integrity sha512-RZ35G0gUXIic0XVFgfPf1wFgFdUpxmHcw270gNzO21cA2KtGjrGKT54jKxRYcD8oAR7cBtSQCilMtYj3h59KvQ==
dependencies:
"@polkadot/api" "^9.3.3"
"@polkadot/extension-inject" "^0.44.6"

"@testing-library/cypress@^8.0.3":
version "8.0.7"
resolved "https://registry.yarnpkg.com/@testing-library/cypress/-/cypress-8.0.7.tgz#18315eba3cf8852808afadf122e4858406384015"
Expand Down

0 comments on commit 7f152ea

Please sign in to comment.