edsadapter 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -0
- package/eslint.config.js +23 -0
- package/index.html +13 -0
- package/package.json +61 -0
- package/public/favicon.svg +1 -0
- package/public/icons.svg +24 -0
- package/src/App.css +184 -0
- package/src/App.tsx +35 -0
- package/src/assets/hero.png +0 -0
- package/src/assets/loading.png +0 -0
- package/src/assets/react.svg +1 -0
- package/src/assets/svg/close.svg +3 -0
- package/src/assets/svg/tick.svg +4 -0
- package/src/assets/vite.svg +1 -0
- package/src/assets/wallet/bitget.png +0 -0
- package/src/assets/wallet/coinbase.png +0 -0
- package/src/assets/wallet/endless.png +0 -0
- package/src/assets/wallet/luffa.png +0 -0
- package/src/assets/wallet/metamask.png +0 -0
- package/src/assets/wallet/okx.png +0 -0
- package/src/assets/wallet/phantom.png +0 -0
- package/src/assets/wallet/tron.png +0 -0
- package/src/assets/wallet/walletConnect.png +0 -0
- package/src/components/Button/index.tsx +9 -0
- package/src/components/ConnectModal/index.css +32 -0
- package/src/components/ConnectModal/index.tsx +77 -0
- package/src/components/ConnectModal/modal.tsx +261 -0
- package/src/components/ConnectModal/showConnectModal.tsx +20 -0
- package/src/components/ConnectModal/styles.ts +46 -0
- package/src/components/Modal.tsx +122 -0
- package/src/config/wallets.ts +98 -0
- package/src/contexts/Modal.tsx +33 -0
- package/src/contexts/Tables.tsx +32 -0
- package/src/hooks/store.ts +30 -0
- package/src/hooks/useIsMobile.ts +10 -0
- package/src/hooks/useSyncProvider.ts +4 -0
- package/src/hooks/useToast.tsx +163 -0
- package/src/hooks/useWallet.ts +66 -0
- package/src/index.css +111 -0
- package/src/index.ts +5 -0
- package/src/main.tsx +5 -0
- package/src/store/connectStore.ts +87 -0
- package/src/theme/components/Button.ts +100 -0
- package/src/theme/components/Checkbox.tsx +24 -0
- package/src/theme/components/Drawer.ts +60 -0
- package/src/theme/components/Input.ts +98 -0
- package/src/theme/components/Menu.ts +52 -0
- package/src/theme/components/Modal.ts +44 -0
- package/src/theme/components/NumberInput.ts +54 -0
- package/src/theme/components/Popover.ts +72 -0
- package/src/theme/components/Progress.ts +41 -0
- package/src/theme/components/Radio.tsx +66 -0
- package/src/theme/components/Switch.ts +30 -0
- package/src/theme/components/Table.ts +149 -0
- package/src/theme/components/Tabs.ts +90 -0
- package/src/theme/components/Tag.ts +21 -0
- package/src/theme/components/Textarea.ts +21 -0
- package/src/theme/components/Tooltip.ts +35 -0
- package/src/theme/index.ts +269 -0
- package/src/types/adapter.d.ts +43 -0
- package/src/types/global.d.ts +102 -0
- package/src/types/type.ts +100 -0
- package/src/web3/ethereum/index.ts +36 -0
- package/src/web3/index.ts +15 -0
- package/src/web3/solana/index.ts +104 -0
- package/src/web3/tron/index.ts +57 -0
- package/tsconfig.app.json +31 -0
- package/tsconfig.json +7 -0
- package/tsconfig.node.json +29 -0
- package/vite.config.ts +31 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { standaloneToast } from '../../hooks/useToast'
|
|
2
|
+
import useConnectStore from '../../store/connectStore'
|
|
3
|
+
import { PublicKey, type SendOptions, Transaction } from '@solana/web3.js'
|
|
4
|
+
import isMobile from 'is-mobile'
|
|
5
|
+
import phantom from '../../assets/wallet/phantom.png'
|
|
6
|
+
|
|
7
|
+
type DisplayEncoding = 'utf8' | 'hex'
|
|
8
|
+
|
|
9
|
+
interface ConnectOpts {
|
|
10
|
+
onlyIfTrusted: boolean
|
|
11
|
+
}
|
|
12
|
+
export type PhantomEvent = 'connect' | 'disconnect' | 'accountChanged'
|
|
13
|
+
|
|
14
|
+
type PhantomRequestMethod =
|
|
15
|
+
| 'connect'
|
|
16
|
+
| 'disconnect'
|
|
17
|
+
| 'signAndSendTransaction'
|
|
18
|
+
| 'signTransaction'
|
|
19
|
+
| 'signAllTransactions'
|
|
20
|
+
| 'signMessage'
|
|
21
|
+
|
|
22
|
+
export interface PhantomProvider {
|
|
23
|
+
publicKey: PublicKey | null
|
|
24
|
+
isConnected: boolean | null
|
|
25
|
+
signAndSendTransaction: (
|
|
26
|
+
transaction: Transaction,
|
|
27
|
+
opts?: SendOptions,
|
|
28
|
+
) => Promise<{ signature: string; publicKey: PublicKey }>
|
|
29
|
+
signTransaction: (transaction: Transaction) => Promise<Transaction>
|
|
30
|
+
signAllTransactions: (transactions: Transaction[]) => Promise<Transaction[]>
|
|
31
|
+
signMessage: (message: Uint8Array | string, display?: DisplayEncoding) => Promise<any>
|
|
32
|
+
connect: (opts?: Partial<ConnectOpts>) => Promise<{ publicKey: PublicKey }>
|
|
33
|
+
disconnect: () => Promise<void>
|
|
34
|
+
on: (event: PhantomEvent, handler: (args: any) => void) => void
|
|
35
|
+
request: (method: PhantomRequestMethod, params?: any) => Promise<unknown>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const getSolProvider = (): PhantomProvider | undefined => {
|
|
39
|
+
if (window && 'phantom' in window) {
|
|
40
|
+
const anyWindow: any = window
|
|
41
|
+
const provider = anyWindow.phantom?.solana
|
|
42
|
+
|
|
43
|
+
if (provider?.isPhantom) {
|
|
44
|
+
return provider
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (window && isMobile()) {
|
|
48
|
+
const currentURl = window.location.href
|
|
49
|
+
const mobile: any = navigator.userAgent.toLowerCase()
|
|
50
|
+
const isSamsung = mobile?.match(/sm-/i) == 'sm-'
|
|
51
|
+
if (isSamsung) {
|
|
52
|
+
window.open(`phantom://browse/${encodeURIComponent(currentURl)}?ref=${encodeURIComponent(currentURl)}`, '_blank')
|
|
53
|
+
} else {
|
|
54
|
+
window.open(
|
|
55
|
+
`https://phantom.app/ul/browse/${encodeURIComponent(currentURl)}?ref=${encodeURIComponent(currentURl)}`,
|
|
56
|
+
'_blank',
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
return
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const getPublicKey = async (img: string) => {
|
|
64
|
+
try {
|
|
65
|
+
const provider = getSolProvider()
|
|
66
|
+
if (provider) {
|
|
67
|
+
await provider?.connect()
|
|
68
|
+
const publicKey = provider?.publicKey!.toString()
|
|
69
|
+
// }
|
|
70
|
+
if (publicKey) {
|
|
71
|
+
useConnectStore.getState().updateAddress(publicKey)
|
|
72
|
+
useConnectStore.getState().setChain('solana:dev')
|
|
73
|
+
useConnectStore.getState().updateWalletIcon(img)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return publicKey
|
|
77
|
+
}
|
|
78
|
+
} catch (error) {
|
|
79
|
+
standaloneToast({
|
|
80
|
+
title: 'error',
|
|
81
|
+
message: 'Please switch to the Solana network and try connecting to the wallet again.',
|
|
82
|
+
status: 'error',
|
|
83
|
+
duration: 3000,
|
|
84
|
+
isClosable: true,
|
|
85
|
+
})
|
|
86
|
+
return error
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const watchSolAccountChange = (provider: any) => {
|
|
91
|
+
provider?.on('accountChanged', (publicKey: { toBase58: () => string }) => {
|
|
92
|
+
console.log('Account changed===>', publicKey.toBase58())
|
|
93
|
+
if (useConnectStore.getState().address) {
|
|
94
|
+
if (publicKey) {
|
|
95
|
+
// Set new public key and continue as usual
|
|
96
|
+
useConnectStore.getState().updateAddress(publicKey.toBase58())
|
|
97
|
+
window.localStorage.setItem('wallet-address', publicKey.toBase58())
|
|
98
|
+
} else {
|
|
99
|
+
getPublicKey(phantom)
|
|
100
|
+
// Attempt to reconnect to Phantom
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import useConnectStore from '../../store/connectStore'
|
|
2
|
+
import { WalletLink } from '../../types/type'
|
|
3
|
+
import isMobile from 'is-mobile'
|
|
4
|
+
|
|
5
|
+
export const getTronProvider = () => {
|
|
6
|
+
if (window.tron) {
|
|
7
|
+
return window.tron
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (window && isMobile()) {
|
|
11
|
+
const currentURl = window.location.href
|
|
12
|
+
|
|
13
|
+
const params = {
|
|
14
|
+
url: currentURl,
|
|
15
|
+
action: 'open',
|
|
16
|
+
protocol: 'tronlink',
|
|
17
|
+
version: '1.0',
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
window.location.href = `tronlinkoutside://pull.activity?param=${encodeURIComponent(JSON.stringify(params))}`
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
window.open(WalletLink.TRONLINK, '_blank')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const getAddress = async (img: string) => {
|
|
28
|
+
try {
|
|
29
|
+
const provider = await getTronProvider()
|
|
30
|
+
|
|
31
|
+
if (provider) {
|
|
32
|
+
const res = await provider.request({
|
|
33
|
+
method: 'eth_requestAccounts',
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const address: string = res[0]
|
|
37
|
+
|
|
38
|
+
// const curChainId = (await provider.request({
|
|
39
|
+
// method: 'eth_chainId',
|
|
40
|
+
// params: [],
|
|
41
|
+
// })) as string
|
|
42
|
+
|
|
43
|
+
// console.log('curChainId===>', curChainId)
|
|
44
|
+
|
|
45
|
+
const chainId: string = useConnectStore.getState().network === 'dev' ? 'Tron-3448148188' : 'Tron-728126428'
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
useConnectStore.getState().updateAddress(address)
|
|
50
|
+
useConnectStore.getState().setChain(chainId)
|
|
51
|
+
useConnectStore.getState().updateWalletIcon(img)
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
} catch (error) {
|
|
55
|
+
return error
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
|
4
|
+
"target": "ES2023",
|
|
5
|
+
"useDefineForClassFields": true,
|
|
6
|
+
"lib": ["ES2023", "DOM", "DOM.Iterable"],
|
|
7
|
+
"module": "ESNext",
|
|
8
|
+
"types": ["vite/client"],
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
|
|
11
|
+
/* Bundler mode */
|
|
12
|
+
"moduleResolution": "bundler",
|
|
13
|
+
"allowImportingTsExtensions": true,
|
|
14
|
+
"verbatimModuleSyntax": true,
|
|
15
|
+
"moduleDetection": "force",
|
|
16
|
+
"noEmit": true,
|
|
17
|
+
"jsx": "react-jsx",
|
|
18
|
+
|
|
19
|
+
/* Linting */
|
|
20
|
+
"strict": true,
|
|
21
|
+
"noUnusedLocals": true,
|
|
22
|
+
"noUnusedParameters": true,
|
|
23
|
+
"erasableSyntaxOnly": true,
|
|
24
|
+
"noFallthroughCasesInSwitch": true,
|
|
25
|
+
"noUncheckedSideEffectImports": true,
|
|
26
|
+
"paths": {
|
|
27
|
+
"@/*": ["./src/*"]
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"include": ["src"]
|
|
31
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
|
4
|
+
"target": "ES2023",
|
|
5
|
+
"lib": ["ES2023"],
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"types": ["node"],
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
|
|
10
|
+
/* Bundler mode */
|
|
11
|
+
"moduleResolution": "bundler",
|
|
12
|
+
"allowImportingTsExtensions": true,
|
|
13
|
+
"verbatimModuleSyntax": true,
|
|
14
|
+
"moduleDetection": "force",
|
|
15
|
+
"noEmit": true,
|
|
16
|
+
|
|
17
|
+
/* Linting */
|
|
18
|
+
"strict": true,
|
|
19
|
+
"noUnusedLocals": true,
|
|
20
|
+
"noUnusedParameters": true,
|
|
21
|
+
"erasableSyntaxOnly": true,
|
|
22
|
+
"noFallthroughCasesInSwitch": true,
|
|
23
|
+
"noUncheckedSideEffectImports": true,
|
|
24
|
+
"paths": {
|
|
25
|
+
"@/*": ["./src/*"]
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"include": ["vite.config.ts"]
|
|
29
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import { defineConfig } from 'vite'
|
|
3
|
+
import react, { reactCompilerPreset } from '@vitejs/plugin-react'
|
|
4
|
+
import babel from '@rolldown/plugin-babel'
|
|
5
|
+
import svgr from "vite-plugin-svgr";
|
|
6
|
+
|
|
7
|
+
// https://vite.dev/config/
|
|
8
|
+
export default defineConfig({
|
|
9
|
+
resolve: {
|
|
10
|
+
alias: [
|
|
11
|
+
{ find: '@', replacement: path.resolve(__dirname, 'src') },
|
|
12
|
+
{ find: 'react', replacement: path.resolve(__dirname, 'node_modules/react') },
|
|
13
|
+
{ find: 'react-dom', replacement: path.resolve(__dirname, 'node_modules/react-dom') },
|
|
14
|
+
{ find: 'react-dom/client', replacement: path.resolve(__dirname, 'node_modules/react-dom/client') },
|
|
15
|
+
],
|
|
16
|
+
},
|
|
17
|
+
plugins: [
|
|
18
|
+
react(),
|
|
19
|
+
babel({ presets: [reactCompilerPreset()] }),
|
|
20
|
+
svgr({
|
|
21
|
+
// svgr options: https://react-svgr.com/docs/options/
|
|
22
|
+
svgrOptions: { icon: true },
|
|
23
|
+
// esbuild options, to transform jsx to js
|
|
24
|
+
esbuildOptions: {},
|
|
25
|
+
// A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should include.
|
|
26
|
+
include: "**/*.svg?react",
|
|
27
|
+
// A minimatch pattern, or array of patterns, which specifies the files in the build the plugin should ignore. By default no files are ignored.
|
|
28
|
+
exclude: "",
|
|
29
|
+
})
|
|
30
|
+
],
|
|
31
|
+
})
|