-
Notifications
You must be signed in to change notification settings - Fork 609
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add SubWallet wallet feat: update change set feat: update custom-wallet-list feat: add WalletConnect and Mobile for SubWallet feat: fix wrong logo path * fix: changeset * fix: rebase * fix: i18n * fix: ordering * fix: i18n key * fix: changeset * fix: i18n keys --------- Co-authored-by: S2kael <laiducminh1002@gmail.com>
- Loading branch information
1 parent
b0022ae
commit efb8566
Showing
7 changed files
with
222 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
'@rainbow-me/rainbowkit': patch | ||
--- | ||
|
||
SubWallet Support | ||
|
||
**Example usage** | ||
|
||
```ts | ||
import { | ||
getDefaultWallets, | ||
connectorsForWallets, | ||
} from '@rainbow-me/rainbowkit'; | ||
import { subWallet } from '@rainbow-me/rainbowkit/wallets'; | ||
const { wallets } = getDefaultWallets({ appName, chains, projectId }); | ||
const connectors = connectorsForWallets([ | ||
...wallets, | ||
{ | ||
groupName: 'Other', | ||
wallets: [subWallet({ chains, projectId })], | ||
}, | ||
]); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/rainbowkit/src/wallets/walletConnectors/subWallet/subWallet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
152 changes: 152 additions & 0 deletions
152
packages/rainbowkit/src/wallets/walletConnectors/subWallet/subWallet.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import type { InjectedConnectorOptions } from '@wagmi/core/connectors/injected'; | ||
import { InjectedConnector } from 'wagmi/connectors/injected'; | ||
import { Chain } from '../../../components/RainbowKitProvider/RainbowKitChainContext'; | ||
import { getWalletConnectUri } from '../../../utils/getWalletConnectUri'; | ||
import { InstructionStepName, Wallet } from '../../Wallet'; | ||
import { | ||
WalletConnectConnectorOptions, | ||
getWalletConnectConnector, | ||
} from '../../getWalletConnectConnector'; | ||
|
||
declare global { | ||
interface Window { | ||
SubWallet: Window['ethereum']; | ||
} | ||
} | ||
|
||
export interface SubWalletOptions { | ||
projectId: string; | ||
chains: Chain[]; | ||
walletConnectVersion?: '2'; | ||
walletConnectOptions?: WalletConnectConnectorOptions; | ||
} | ||
|
||
const getSubWalletInjectedProvider = (): Window['ethereum'] => { | ||
if (typeof window === 'undefined') return; | ||
return window.SubWallet; | ||
}; | ||
|
||
export const subWallet = ({ | ||
chains, | ||
projectId, | ||
walletConnectOptions, | ||
walletConnectVersion = '2', | ||
...options | ||
}: SubWalletOptions & InjectedConnectorOptions): Wallet => { | ||
const isSubWalletInjected = Boolean(getSubWalletInjectedProvider()); | ||
const shouldUseWalletConnect = !isSubWalletInjected; | ||
|
||
return { | ||
id: 'subwallet', | ||
name: 'SubWallet', | ||
iconUrl: async () => (await import('./subWallet.svg')).default, | ||
iconBackground: '#fff', | ||
installed: isSubWalletInjected || undefined, | ||
downloadUrls: { | ||
browserExtension: 'https://www.subwallet.app/download', | ||
chrome: | ||
'https://chrome.google.com/webstore/detail/subwallet-polkadot-wallet/onhogfjeacnfoofkfgppdlbmlmnplgbn', | ||
firefox: 'https://addons.mozilla.org/en-US/firefox/addon/subwallet/', | ||
edge: 'https://chrome.google.com/webstore/detail/subwallet-polkadot-wallet/onhogfjeacnfoofkfgppdlbmlmnplgbn', | ||
mobile: 'https://www.subwallet.app/download', | ||
android: | ||
'https://play.google.com/store/apps/details?id=app.subwallet.mobile', | ||
ios: 'https://apps.apple.com/us/app/subwallet-polkadot-wallet/id1633050285', | ||
qrCode: 'https://www.subwallet.app/download', | ||
}, | ||
createConnector: () => { | ||
const connector = shouldUseWalletConnect | ||
? getWalletConnectConnector({ | ||
projectId, | ||
chains, | ||
version: walletConnectVersion, | ||
options: walletConnectOptions, | ||
}) | ||
: new InjectedConnector({ | ||
chains, | ||
options: { | ||
getProvider: getSubWalletInjectedProvider, | ||
...options, | ||
}, | ||
}); | ||
|
||
const getUriMobile = async () => { | ||
const uri = await getWalletConnectUri(connector, walletConnectVersion); | ||
|
||
return `subwallet://wc?uri=${encodeURIComponent(uri)}`; | ||
}; | ||
|
||
const getUriQR = async () => { | ||
return await getWalletConnectUri(connector, walletConnectVersion); | ||
}; | ||
|
||
const mobileConnector = { | ||
getUri: shouldUseWalletConnect ? getUriMobile : undefined, | ||
}; | ||
|
||
let qrConnector = undefined; | ||
|
||
if (shouldUseWalletConnect) { | ||
qrConnector = { | ||
getUri: getUriQR, | ||
instructions: { | ||
learnMoreUrl: 'https://www.subwallet.app/', | ||
steps: [ | ||
{ | ||
description: | ||
'wallet_connectors.subwallet.qr_code.step1.description', | ||
step: 'install' as InstructionStepName, | ||
title: 'wallet_connectors.subwallet.qr_code.step1.title', | ||
}, | ||
{ | ||
description: | ||
'wallet_connectors.subwallet.qr_code.step2.description', | ||
step: 'create' as InstructionStepName, | ||
title: 'wallet_connectors.subwallet.qr_code.step2.title', | ||
}, | ||
{ | ||
description: | ||
'wallet_connectors.subwallet.qr_code.step3.description', | ||
step: 'scan' as InstructionStepName, | ||
title: 'wallet_connectors.subwallet.qr_code.step3.title', | ||
}, | ||
], | ||
}, | ||
}; | ||
} | ||
|
||
const extensionConnector = { | ||
instructions: { | ||
learnMoreUrl: 'https://www.subwallet.app/', | ||
steps: [ | ||
{ | ||
description: | ||
'wallet_connectors.subwallet.extension.step1.description', | ||
step: 'install' as InstructionStepName, | ||
title: 'wallet_connectors.subwallet.extension.step1.title', | ||
}, | ||
{ | ||
description: | ||
'wallet_connectors.subwallet.extension.step2.description', | ||
step: 'create' as InstructionStepName, | ||
title: 'wallet_connectors.subwallet.extension.step2.title', | ||
}, | ||
{ | ||
description: | ||
'wallet_connectors.subwallet.extension.step3.description', | ||
step: 'refresh' as InstructionStepName, | ||
title: 'wallet_connectors.subwallet.extension.step3.title', | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
return { | ||
connector, | ||
mobile: mobileConnector, | ||
qrCode: qrConnector, | ||
extension: extensionConnector, | ||
}; | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
efb8566
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
rainbowkit-site – ./
rainbowkit-site-rainbowdotme.vercel.app
v2-rainbowkit.vercel.app
v1-rainbowkit.vercel.app
rainbowkit.vercel.app
rainbowkit-site-git-main-rainbowdotme.vercel.app
www.rainbowkit.com
rainbowkit.com
efb8566
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
rainbowkit-example – ./
rainbowkit-example.vercel.app
rainbowkit-example-rainbowdotme.vercel.app
rainbowkit-example-git-main-rainbowdotme.vercel.app