-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support telegram mini app (#199)
* feat: Add `ConnectWithWalletConnect` view * feat: support TMA * feat: Support telegram mini app
- Loading branch information
Showing
35 changed files
with
482 additions
and
166 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,5 @@ | ||
--- | ||
'@node-real/walletkit': patch | ||
--- | ||
|
||
Support telegram mini app |
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
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
6 changes: 3 additions & 3 deletions
6
packages/walletkit/src/evm/components/EvmConnectWithQRCodeView/index.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
65 changes: 65 additions & 0 deletions
65
packages/walletkit/src/evm/components/EvmConnectWithWalletConnectView/index.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,65 @@ | ||
import { CONNECT_STATUS } from '@/core/constants'; | ||
import { ConnectingView } from '@/core/modals/ConnectModal/ConnectingView'; | ||
import { useLogger, useSelectedWallet } from '@/core/providers/WalletKitProvider/context'; | ||
import { useEvmIsConnected } from '@/evm/hooks/useEvmIsConnected'; | ||
import { useWalletConnectUri } from '@/evm/hooks/useWalletConnectUri'; | ||
import { EvmWallet } from '@/evm/wallets'; | ||
import { useCallback, useState } from 'react'; | ||
|
||
export function EvmConnectWithWalletConnectView() { | ||
const { selectedWallet } = useSelectedWallet(); | ||
|
||
const log = useLogger(); | ||
const [status, setStatus] = useState(CONNECT_STATUS.CONNECTING); | ||
|
||
const wcUri = useWalletConnectUri({ | ||
onError(error: any) { | ||
if (error.code) { | ||
// https://github.com/MetaMask/eth-rpc-errors/blob/main/src/error-constants.ts | ||
switch (error.code) { | ||
case -32002: | ||
setStatus(CONNECT_STATUS.NOTCONNECTED); | ||
break; | ||
case 4001: | ||
setStatus(CONNECT_STATUS.REJECTED); | ||
break; | ||
default: | ||
setStatus(CONNECT_STATUS.FAILED); | ||
break; | ||
} | ||
} else { | ||
// Sometimes the error doesn't respond with a code | ||
if (error.message) { | ||
switch (error.message) { | ||
case 'User rejected request': | ||
setStatus(CONNECT_STATUS.REJECTED); | ||
break; | ||
default: | ||
setStatus(CONNECT_STATUS.FAILED); | ||
break; | ||
} | ||
} | ||
} | ||
}, | ||
}); | ||
|
||
const walletUri = (selectedWallet as EvmWallet).getUri(wcUri); | ||
const isConnected = useEvmIsConnected(); | ||
|
||
const onClickConnect = useCallback(() => { | ||
log(`[connectWithWalletConnect] walletUri`, walletUri); | ||
setStatus(CONNECT_STATUS.CONNECTING); | ||
window.open(walletUri, '_self', 'noopener noreferrer'); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [walletUri]); | ||
|
||
return ( | ||
<ConnectingView | ||
isConnected={isConnected} | ||
status={status} | ||
runConnect={onClickConnect} | ||
wallet={selectedWallet} | ||
isReady={!!wcUri} | ||
/> | ||
); | ||
} |
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.