forked from blocknative/web3-onboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add substrate wallet into wallet module list, and resolve transaction…
… off WalletConnect for substrate account
- Loading branch information
1 parent
95de42e
commit ca0186c
Showing
28 changed files
with
839 additions
and
24 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
{ | ||
"name": "@subwallet_connect/polkadot_js", | ||
"version": "1.0.0", | ||
"description": "Polkadot{.js} Wallet SDK wallet module for connecting to Web3-Onboard. Web3-Onboard makes it simple to connect Ethereum hardware and software wallets to your dapp. Features standardized spec compliant web3 providers for all supported wallets, framework agnostic modern javascript UI with code splitting, CSS customization, multi-chain and multi-account support, reactive wallet state subscriptions and real-time transaction state change notifications.", | ||
"keywords": [ | ||
"Ethereum", | ||
"Web3", | ||
"EVM", | ||
"dapp", | ||
"Multichain", | ||
"Wallet", | ||
"Transaction", | ||
"Provider", | ||
"Hardware Wallet", | ||
"Notifications", | ||
"React", | ||
"Svelte", | ||
"Vue", | ||
"Next", | ||
"Nuxt", | ||
"MetaMask", | ||
"Coinbase", | ||
"WalletConnect", | ||
"Ledger", | ||
"Trezor", | ||
"Connect Wallet", | ||
"Ethereum Hooks", | ||
"Blocknative", | ||
"Mempool", | ||
"pending", | ||
"confirmed", | ||
"Injected Wallet", | ||
"Crypto", | ||
"Crypto Wallet", | ||
"Enkrypt", | ||
"SubWallet" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/blocknative/web3-onboard.git", | ||
"directory": "packages/subwallet" | ||
}, | ||
"homepage": "https://www.blocknative.com/onboard", | ||
"bugs": { | ||
"url": "https://github.com/blocknative/web3-onboard/issues" | ||
}, | ||
"module": "dist/index.js", | ||
"browser": "dist/index.js", | ||
"main": "dist/index.js", | ||
"type": "module", | ||
"typings": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "tsc", | ||
"dev": "tsc -w", | ||
"type-check": "tsc --noEmit" | ||
}, | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@polkadot/dev": "^0.78.7", | ||
"typescript": "^4.5.5", | ||
"window": "^4.2.7", | ||
"@types/node": "17.0.19" | ||
}, | ||
"dependencies": { | ||
"@polkadot/extension-inject": "^0.46.5", | ||
"@subwallet_connect/common": "^1.0.2", | ||
"events": "^3.3.0" | ||
}, | ||
"author": "" | ||
} |
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,6 @@ | ||
export const DAPP_NAME = 'SubConnect'; | ||
|
||
export const EXTENSION_NAME = 'polkadot-js'; | ||
|
||
|
||
export const URL_INSTALL = 'https://polkadot.js.org/extension' |
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,12 @@ | ||
export default ` | ||
<svg width="100%" height="100%" viewBox="0 0 40 40" fill="none" xmlns="http://www.w3.org/2000/svg"> | ||
<mask id="mask0_16261_2383" style="mask-type:alpha" maskUnits="userSpaceOnUse" x="0" y="0" width="40" height="40"> | ||
<path d="M20 0C35.1658 0 40 4.83421 40 20C40 35.1658 35.1658 40 20 40C4.83421 40 0 35.1658 0 20C0 4.83421 4.83421 0 20 0Z" fill="#004BFF"/> | ||
</mask> | ||
<g mask="url(#mask0_16261_2383)"> | ||
<rect width="40" height="40" fill="#FF8C00"/> | ||
</g> | ||
<path d="M20.1266 8.71466C15.4176 8.71466 11.5689 12.5407 11.5689 17.2723C11.5689 18.2232 11.7274 19.1514 12.0217 20.0569C12.2254 20.6682 12.9046 21.0078 13.5385 20.804C14.1498 20.6003 14.4894 19.9211 14.2856 19.2872C14.0366 18.5854 13.9234 17.8383 13.946 17.0912C14.0366 13.8991 16.6175 11.2729 19.8096 11.1144C23.364 10.9333 26.3071 13.7632 26.3071 17.2723C26.3071 20.555 23.7262 23.2491 20.4888 23.4302C20.4888 23.4302 19.2889 23.4981 18.7003 23.5887C18.406 23.634 18.1796 23.6792 18.0211 23.7019C17.9532 23.7245 17.8853 23.6566 17.9079 23.5887L18.1117 22.5925L19.221 17.4761C19.3568 16.8422 18.9493 16.2083 18.3154 16.0724C17.6815 15.9366 17.0476 16.3441 16.9118 16.978C16.9118 16.978 14.2403 29.4296 14.2177 29.5654C14.0819 30.1993 14.4894 30.8332 15.1233 30.9691C15.7572 31.1049 16.3911 30.6974 16.5269 30.0635C16.5496 29.9277 16.9118 28.275 16.9118 28.275C17.1835 27.0072 18.2249 26.079 19.4474 25.9205C19.7191 25.8752 20.7831 25.8073 20.7831 25.8073C25.1978 25.4677 28.6842 21.7775 28.6842 17.2723C28.6842 12.5407 24.8355 8.71466 20.1266 8.71466ZM20.7378 28.4108C19.9681 28.2524 19.1983 28.7278 19.0399 29.5202C18.8814 30.2899 19.3568 31.0596 20.1492 31.2181C20.9189 31.3766 21.6887 30.9012 21.8471 30.1088C22.0056 29.3164 21.5302 28.5693 20.7378 28.4108Z" fill="white"/> | ||
</svg> | ||
` |
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,92 @@ | ||
import type { WalletInit, EIP1193Provider } from '@subwallet_connect/common' | ||
import { SubstrateProvider, WalletInterfaceSubstrate} from "@subwallet_connect/common"; | ||
import { InjectedMetadata, InjectedWindow } from "@polkadot/extension-inject/types"; | ||
import EventEmitter from "events"; | ||
import { Signer } from "@polkadot/types/types"; | ||
import { EXTENSION_NAME, DAPP_NAME, URL_INSTALL} from "./constant.js"; | ||
|
||
function SubWallet (): WalletInit { | ||
if (typeof window === 'undefined') return () => null | ||
|
||
return () => { | ||
|
||
return { | ||
label: 'Polkadot{.js}', | ||
type: 'substrate', | ||
getIcon: async () => (await import('./icon.js')).default, | ||
platforms: ['desktop'], | ||
getInterface: async (): Promise<WalletInterfaceSubstrate> => { | ||
const isInstalled = (extensionName: string) => { | ||
const injectedWindow = window as unknown as Window & InjectedWindow; | ||
const injectedExtension = | ||
injectedWindow?.injectedWeb3[extensionName] | ||
return !!injectedExtension; | ||
} | ||
|
||
if(!isInstalled(EXTENSION_NAME)){ | ||
window.open(URL_INSTALL, '_blank'); | ||
throw new Error('Please Install Polkadot{.js} wallet to use this wallet'); | ||
} | ||
const getRawExtension = (extensionName: string) => { | ||
const injectedWindow = window as unknown as Window & InjectedWindow; | ||
return injectedWindow?.injectedWeb3[extensionName]; | ||
} | ||
const emitter = new EventEmitter() | ||
const provider: SubstrateProvider = { | ||
async enable() { | ||
|
||
try { | ||
const injectedExtension = getRawExtension(EXTENSION_NAME); | ||
|
||
if (!injectedExtension || !injectedExtension.enable) { | ||
return; | ||
} | ||
|
||
const rawExtension = await injectedExtension.enable(DAPP_NAME); | ||
if (!rawExtension) { | ||
return; | ||
} | ||
const accounts = await rawExtension.accounts.get(); | ||
|
||
return { | ||
signer: rawExtension.signer as Signer, | ||
metadata: rawExtension.metadata as InjectedMetadata, | ||
address: accounts.map( | ||
(account: { address: string }) => account.address | ||
) | ||
} | ||
} catch (e) { | ||
console.log('error', (e as Error).message); | ||
} | ||
}, | ||
async signDummy(address: string, data: string, | ||
signer: Signer) { | ||
if (signer && signer.signRaw) { | ||
return (await signer.signRaw({ | ||
address: address, | ||
data: 'This is dummy message', | ||
type: 'bytes' | ||
})).signature as string; | ||
} | ||
return '0x0' | ||
}, | ||
|
||
async request() {}, | ||
|
||
async disconnect() {}, | ||
|
||
on: emitter.on.bind(emitter), | ||
removeListener: emitter.removeListener.bind(emitter) | ||
|
||
} | ||
|
||
return { | ||
provider | ||
} | ||
}, | ||
} | ||
} | ||
|
||
} | ||
|
||
export default SubWallet |
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,16 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": ["src/**/*"], | ||
|
||
"compilerOptions": { | ||
"outDir": "dist", | ||
"rootDir": "src", | ||
"allowSyntheticDefaultImports": true, | ||
"declaration": true, | ||
"declarationDir": "dist", | ||
"paths": { | ||
"*": ["./src/*", "./node_modules/*"] | ||
}, | ||
"typeRoots": ["node_modules/@types"] | ||
} | ||
} |
Oops, something went wrong.