Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[react, wallets] Add imToken Wallet (#2497)
Signed-off-by: Mako Shan <imakoshan@gmail.com> Signed-off-by: Jonas Daniels <jonas.daniels@outlook.com> Co-authored-by: xwartz <stddup@gmail.com> Co-authored-by: Jonas Daniels <jonas.daniels@outlook.com>
- Loading branch information
1 parent
9c884e2
commit 79c9e13
Showing
19 changed files
with
317 additions
and
2 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,7 @@ | ||
--- | ||
"@thirdweb-dev/wallets": patch | ||
"@thirdweb-dev/react": patch | ||
"@thirdweb-dev/react-core": patch | ||
--- | ||
|
||
Add imToken Wallet |
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 |
---|---|---|
|
@@ -111,4 +111,5 @@ export { | |
CryptoDefiWallet, | ||
RabbyWallet, | ||
Coin98Wallet, | ||
ImTokenWallet, | ||
} from "@thirdweb-dev/wallets"; |
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
73 changes: 73 additions & 0 deletions
73
packages/react/src/wallet/wallets/imtoken/imTokenWallet.tsx
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 @@ | ||
import type { | ||
WalletOptions, | ||
WalletConfig, | ||
ConnectUIProps, | ||
} from "@thirdweb-dev/react-core"; | ||
import { ImTokenWallet, assertWindowEthereum } from "@thirdweb-dev/wallets"; | ||
import { useTWLocale } from "../../../evm/providers/locale-provider"; | ||
import { ExtensionOrWCConnectionUI } from "../_common/ExtensionORWCConnectionUI"; | ||
|
||
const imTokenWalletUris = { | ||
ios: "https://itunes.apple.com/us/app/imtoken2/id1384798940", | ||
android: "https://play.google.com/store/apps/details?id=im.token.app", | ||
}; | ||
|
||
export type ImTokenWalletConfigOptions = { | ||
projectId?: string; | ||
recommended?: boolean; | ||
}; | ||
|
||
export const imTokenWallet = ( | ||
options?: ImTokenWalletConfigOptions, | ||
): WalletConfig<ImTokenWallet> => { | ||
return { | ||
id: ImTokenWallet.id, | ||
recommended: options?.recommended, | ||
meta: { | ||
...ImTokenWallet.meta, | ||
iconURL: | ||
"data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iODAiIGhlaWdodD0iODAiIHZpZXdCb3g9IjAgMCA4MCA4MCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGcgY2xpcC1wYXRoPSJ1cmwoI2Ns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9InVzZXJTcGFjZU9uVXNlIj4KPHN0b3Agc3RvcC1jb2xvcj0iIzExQzREMSIvPgo8c3RvcCBvZmZzZXQ9IjEiIHN0b3AtY29sb3I9IiMwMDYyQUQiLz4KPC9saW5lYXJHcmFkaWVudD4KPGNsaXBQYXRoIGlkPSJjbGlwMF8yMjJfNDc4MyI+CjxyZWN0IHdpZHRoPSI4MCIgaGVpZ2h0PSI4MCIgZmlsbD0id2hpdGUiLz4KPC9jbGlwUGF0aD4KPC9kZWZzPgo8L3N2Zz4=", | ||
}, | ||
create: (walletOptions: WalletOptions) => { | ||
const wallet = new ImTokenWallet({ | ||
...walletOptions, | ||
projectId: options?.projectId, | ||
qrcode: false, | ||
}); | ||
|
||
return wallet; | ||
}, | ||
connectUI: ConnectUI, | ||
isInstalled: isInstalled, | ||
}; | ||
}; | ||
|
||
function isInstalled() { | ||
if (assertWindowEthereum(globalThis.window)) { | ||
return !!globalThis.window.ethereum.isImToken; | ||
} | ||
return false; | ||
} | ||
|
||
function ConnectUI(props: ConnectUIProps<ImTokenWallet>) { | ||
const locale = useTWLocale(); | ||
return ( | ||
<ExtensionOrWCConnectionUI | ||
connect={props.connect} | ||
connected={props.connected} | ||
createWalletInstance={props.createWalletInstance} | ||
goBack={props.goBack} | ||
meta={props.walletConfig.meta} | ||
setConnectedWallet={(w) => props.setConnectedWallet(w as ImTokenWallet)} | ||
setConnectionStatus={props.setConnectionStatus} | ||
supportedWallets={props.supportedWallets} | ||
walletConnectUris={{ | ||
ios: imTokenWalletUris.ios, | ||
android: imTokenWalletUris.android, | ||
other: imTokenWalletUris.android, | ||
}} | ||
walletLocale={locale.wallets.imTokenWallet} | ||
isInstalled={isInstalled} | ||
/> | ||
); | ||
} |
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,7 @@ | ||
{ | ||
"main": "dist/thirdweb-dev-wallets-evm-connectors-imtoken.cjs.js", | ||
"module": "dist/thirdweb-dev-wallets-evm-connectors-imtoken.esm.js", | ||
"browser": { | ||
"./dist/thirdweb-dev-wallets-evm-connectors-imtoken.esm.js": "./dist/thirdweb-dev-wallets-evm-connectors-imtoken.browser.esm.js" | ||
} | ||
} |
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,7 @@ | ||
{ | ||
"main": "dist/thirdweb-dev-wallets-evm-wallets-imtoken.cjs.js", | ||
"module": "dist/thirdweb-dev-wallets-evm-wallets-imtoken.esm.js", | ||
"browser": { | ||
"./dist/thirdweb-dev-wallets-evm-wallets-imtoken.esm.js": "./dist/thirdweb-dev-wallets-evm-wallets-imtoken.browser.esm.js" | ||
} | ||
} |
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,48 @@ | ||
import { InjectedConnector, InjectedConnectorOptions } from "../injected"; | ||
import { assertWindowEthereum } from "../../utils/assertWindowEthereum"; | ||
import { Ethereum } from "../injected/types"; | ||
import type { Chain } from "@thirdweb-dev/chains"; | ||
import { AsyncStorage } from "../../../core/AsyncStorage"; | ||
|
||
type ImTokenConnectorConstructorArg = { | ||
chains?: Chain[]; | ||
connectorStorage: AsyncStorage; | ||
options?: InjectedConnectorOptions; | ||
}; | ||
|
||
export class ImTokenConnector extends InjectedConnector { | ||
constructor(arg: ImTokenConnectorConstructorArg) { | ||
const defaultOptions = { | ||
name: "imToken", | ||
getProvider() { | ||
function getReady(ethereum?: Ethereum) { | ||
const isToken = !!ethereum?.isToken; | ||
if (!isToken) { | ||
return; | ||
} | ||
return ethereum; | ||
} | ||
|
||
if (typeof window === "undefined") { | ||
return; | ||
} | ||
if (assertWindowEthereum(globalThis.window)) { | ||
if (globalThis.window.ethereum?.providers) { | ||
return globalThis.window.ethereum.providers.find(getReady); | ||
} | ||
|
||
return getReady(globalThis.window.ethereum); | ||
} | ||
}, | ||
}; | ||
const options = { | ||
...defaultOptions, | ||
...arg.options, | ||
}; | ||
super({ | ||
chains: arg.chains, | ||
options, | ||
connectorStorage: arg.connectorStorage, | ||
}); | ||
} | ||
} |
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
Oops, something went wrong.