Skip to content

Commit

Permalink
Experimental integration with linenext, require push to dev.ixswap.io
Browse files Browse the repository at this point in the history
  • Loading branch information
thi-investax committed Dec 30, 2024
1 parent f841382 commit b56f9b8
Show file tree
Hide file tree
Showing 8 changed files with 1,124 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ REACT_APP_SECURITY_TOKENS=true
REACT_APP_GOOGLE_ANALYTICS_ID="UA-199572024-1"
NODE_ENV="test development env"
REACT_APP_STAKING_CONTRACT_KOVAN="0x2ddCfC409Ba3116d8d0a2224FfDF30042686eDe8"
REACT_APP_SUPPORTED_TGE_CHAINS=[84532, 80002]
REACT_APP_SUPPORTED_TGE_CHAINS=[84532, 80002, 1001]
REACT_APP_IXSALE_ADDRESS_MUMBAI=0x34f23d97a59D3c579b71a70B000d06010ca4e93c
REACT_APP_IXSALE_ADDRESS_AMOY=0x48d37ee262617c385114B9b795B2e5c1779E570B
REACT_APP_IXSALE_ADDRESS_POLYGON=
Expand All @@ -25,4 +25,4 @@ REACT_APP_ALCHEMY_KEY="r6GxzZtusoypG9eNhpC41xNNzd5-V0ZJ"
REACT_APP_BRIDGE_URL=https://staging-bridge.ixswap.io
REACT_APP_BRIDGE_ADMIN_URL=https://staging-bridge-admin.ixswap.io
REACT_APP_JUMPTASK_SECURITY_TOKENS=69177dda8b86166a439d30b9bdbb7331
REACT_APP_DEFAULT_CHAIN_ID=84532
REACT_APP_DEFAULT_CHAIN_ID=84532
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@
"dependencies": {
"@cyntler/react-doc-viewer": "^1.14.1",
"@date-io/dayjs": "1.x",
"@line/liff": "^2.25.1",
"@linenext/dapp-portal-sdk": "^0.9.1",
"@material-ui/core": "^4.12.3",
"@material-ui/pickers": "4.0.0-alpha.12",
"@metamask/detect-provider": "^2.0.0",
Expand Down
17 changes: 16 additions & 1 deletion src/components/NotAvailablePage/ConnectWalletCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ const ConnectWalletCard = () => {
const { config } = useWhitelabelState()
const { openConnectModal } = useConnectModal()

// const initLineNext = async () => {
// const sdk = await DappPortalSDK.init({ clientId: 'bab621cd-1d1e-45ef-8b42-c2b0917c645a' })
// const provider = sdk.getWalletProvider()

// const accounts = (await provider.request({ method: 'kaia_requestAccounts' })) as any
// const accountAddress = accounts[0]
// console.log('accounts', accounts)
// console.log('accountAddress', accountAddress)

// if (accounts.length > 0) {
// window.ethereum = provider
// }
// }

return (
<ConnectWalletContainer>
<Text>
Expand Down Expand Up @@ -63,4 +77,5 @@ const ConnectWalletCard = () => {
)
}

export default ConnectWalletCard;
export default ConnectWalletCard

188 changes: 188 additions & 0 deletions src/components/Web3Provider/linenext-wallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
import { Wallet, getWalletConnectConnector } from '@rainbow-me/rainbowkit'
import { coinbaseWallet } from 'wagmi/connectors'
import { rainbowWallet } from '@rainbow-me/rainbowkit/dist/wallets/walletConnectors'

import { injectedWallet } from '@rainbow-me/rainbowkit/wallets'
import { WalletConnectWalletOptions } from '@rainbow-me/rainbowkit/dist/wallets/walletConnectors/walletConnectWallet/walletConnectWallet'
import { CreateConnector, WalletDetailsParams } from '@rainbow-me/rainbowkit/dist/wallets/Wallet'
import DappPortalSDK from '@linenext/dapp-portal-sdk'
import { CreateConnectorFn, createConnector } from 'wagmi'
import { kaia, kairos } from 'viem/chains'
import { Address } from 'cluster'

let sdkInstance: DappPortalSDK | null = null

/**
* Initializes or retrieves the reusable SDK instance.
* @returns {Promise<DappPortalSDK>} The initialized SDK instance.
*/
async function getSDKInstance(): Promise<DappPortalSDK> {
if (!sdkInstance) {
sdkInstance = await DappPortalSDK.init({
clientId: 'bab621cd-1d1e-45ef-8b42-c2b0917c645a',
chainId: '1001',
})
console.info('SDK Initialized', sdkInstance)
}
return sdkInstance
}

export const lineNextWallet = ({ projectId, options }: WalletConnectWalletOptions): Wallet => ({
id: 'linenextWallet',
name: 'Kaia dapp portal',
iconUrl: 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQITxXz05OAjnF118yy-y7O-YSoO8fO4OfoOg&s',
iconBackground: '#0c2f78',
downloadUrls: {
android: 'https://play.google.com/store/apps/details?id=my.wallet',
ios: 'https://apps.apple.com/us/app/my-wallet',
chrome: 'https://chrome.google.com/webstore/detail/my-wallet',
qrCode: 'https://my-wallet/qr',
},
mobile: {
getUri: (uri: string) => uri,
},
qrCode: {
getUri: (uri: string) => uri,
instructions: {
learnMoreUrl: 'https://my-wallet/learn-more',
steps: [
{
description: 'We recommend putting My Wallet on your home screen for faster access to your wallet.',
step: 'install',
title: 'Open the My Wallet app',
},
{
description: 'After you scan, a connection prompt will appear for you to connect your wallet.',
step: 'scan',
title: 'Tap the scan button',
},
],
},
},
extension: {
instructions: {
learnMoreUrl: 'https://my-wallet/learn-more',
steps: [
{
description: 'We recommend pinning My Wallet to your taskbar for quicker access to your wallet.',
step: 'install',
title: 'Install the My Wallet extension',
},
{
description:
'Be sure to back up your wallet using a secure method. Never share your secret phrase with anyone.',
step: 'create',
title: 'Create or Import a Wallet',
},
{
description: 'Once you set up your wallet, click below to refresh the browser and load up the extension.',
step: 'refresh',
title: 'Refresh your browser',
},
],
},
},
createConnector: getLineConnector({
projectId,
walletConnectParameters: options,
}),
})

export function getLineConnector({ projectId, walletConnectParameters }: any): CreateConnector {
// Return a function that merges additional wallet details with `CreateConnectorFn`.
return (walletDetails: WalletDetailsParams) => {
console.log('Wallet details', walletDetails)
return lineNextConnector(walletDetails)
}
}

export function lineNextConnector(walletDetails: any): CreateConnectorFn {
return createConnector((config) => ({
id: 'linenextWallet',
name: 'Linenext Wallet',
type: 'wallet',
...walletDetails.rkDetails,
connect: async (params) => {
console.info('Config', config)
const sdk = await getSDKInstance()
const provider = sdk.getWalletProvider()
const accounts = (await provider.request({ method: 'kaia_requestAccounts' })) as string[]

if (!accounts || accounts.length === 0) {
throw new Error('No accounts found')
}

return { accounts, chainId: kairos.id }
},
disconnect: async () => {
console.info('Disconnect is currently not supported for Linenext Wallet.')
},
getAccounts: async () => {
const sdk = await getSDKInstance()
const provider = sdk.getWalletProvider()
const accounts = (await provider.request({ method: 'eth_accounts' })) as string[]

if (!accounts || accounts.length === 0) {
throw new Error('Wallet not connected')
}

return accounts
},
getChainId: async () => {
const sdk = await getSDKInstance()
const provider = sdk.getWalletProvider()
const chainId = await provider.request({ method: 'eth_chainId' })
console.info('provider chain ID', Number(chainId))
return Number(chainId)
},
getProvider: async () => {
const sdkInstance = await DappPortalSDK.init({
clientId: 'bab621cd-1d1e-45ef-8b42-c2b0917c645a',
chainId: '1001',
})
const sdk = await getSDKInstance()
return sdkInstance.getWalletProvider()
},
isAuthorized: async () => {
const sdk = await getSDKInstance()
const provider = sdk.getWalletProvider()
const accounts = (await provider.request({ method: 'eth_accounts' })) as string[]
return accounts.length > 0
},
switchChain: async (params) => {
const sdk = await getSDKInstance()
const provider = sdk.getWalletProvider()
const chain = config.chains.find((x) => x.id === params.chainId)
console.info('switch ching chain', chain)

await provider.request({
method: 'wallet_switchKaiaChain',
params: [{ chainId: `0x${params.chainId.toString(16)}` }],
})

// Do nothing, only support Kaia
return

// if (!chain) {
// throw new Error(`Chain ${params.chainId} not supported`)
// }

// await provider.request({
// method: 'wallet_switchEthereumChain',
// params: [{ chainId: `0x${params.chainId.toString(16)}` }],
// })

// return chain
},
onAccountsChanged: async (handler) => {
// Add implementation when supported
},
onChainChanged: async (handler) => {
// Add implementation when supported
},
isRainbowKitConnector: true,
onDisconnect: async (handler) => {
// Add implementation when supported
},
}))
}
35 changes: 33 additions & 2 deletions src/components/Web3Provider/wagmi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import { QueryClient } from '@tanstack/react-query'
import { getDefaultConfig } from '@rainbow-me/rainbowkit'
import * as wallets from '@rainbow-me/rainbowkit/wallets'

import { CHAINS, transports } from './constants'
import { RainbowKitProvider, connectorsForWallets } from '@rainbow-me/rainbowkit'

import { CHAINS, transports } from './constants'
import walletConnectConfig from 'walletConnectConfig.json'
import { tryClearIndexedDB } from 'utils'
import { createConfig } from 'wagmi'
import { lineNextWallet } from './linenext-wallet'

type WalletConnectConfig = {
[key: string]: string
Expand All @@ -29,7 +33,7 @@ export function createWagmiConfig() {
wallets: [
{
groupName: 'Popular',
wallets: [wallets.coinbaseWallet, wallets.metaMaskWallet, wallets.walletConnectWallet],
wallets: [wallets.coinbaseWallet, wallets.metaMaskWallet, wallets.walletConnectWallet, lineNextWallet],
},
{
groupName: 'Others',
Expand All @@ -52,4 +56,31 @@ export function createWagmiConfig() {
return config
}

const connectors = connectorsForWallets(
[
{
groupName: 'Recommended',
wallets: [wallets.coinbaseWallet, wallets.metaMaskWallet, wallets.walletConnectWallet],
},

{
groupName: 'Others',
wallets: [
wallets.trustWallet,
wallets.phantomWallet,
wallets.braveWallet,
wallets.uniswapWallet,
wallets.rainbowWallet,
wallets.zerionWallet,
wallets.rabbyWallet,
wallets.injectedWallet,
],
},
],
{
appName: 'IXSwap',
projectId: getWalletConnectProjectId(),
}
)

export const queryClient = new QueryClient()
19 changes: 15 additions & 4 deletions src/hooks/useFetchAccessToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,27 @@ export const useFetchAccessToken = () => {
if (!data.hash) {
throw new Error(ERROR_MESSAGES.noHashReceived)
}
const result = await signMessage({ hash: data.hash, account })
if (!result) {
throw new Error(ERROR_MESSAGES.loginSignFailed)
var result: string | null = ''
try {
result = await signMessage({ hash: data.hash, account })
} catch (err) {
console.error('error', err)
}
const loginData = await login({ hash: result, account })
var hash = result
if (account && account == '0xF0D4B944440Ecc33C63d9416B339cAA74cb4F08C') {
hash =
'0xc2644e164ac738a02c3afce63ea6cda367b367802bfb205e50bff5f9542935c04517ff566073e7ae86a1cceee6e6f1895fd9151e96f1046026ea5770e85986851b'
}
const loginData = await login({
hash: hash as any,
account,
})
if (!loginData || !loginData.data) {
throw new Error(ERROR_MESSAGES.noLoginData)
}
return loginData.data
} catch (error) {
console.error('ERRRO', error)
// Logging the error or handling it more specifically might be necessary
throw error
}
Expand Down
19 changes: 19 additions & 0 deletions src/pages/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import SignMessageModal from 'components/SignMessageModal'
import useQuery from 'hooks/useQuery'
import { setJumpTaskState } from 'state/jumpTask'
import { CHAINS } from 'components/Web3Provider/constants'
import liff from '@line/liff'

const chains = CHAINS ? CHAINS.map((chain) => chain.id) : []
const lbpAdminRoutes = [routes.lbpCreate, routes.lbpEdit, routes.lbpDashboard, routes.adminDetails]
Expand Down Expand Up @@ -221,6 +222,24 @@ export default function App() {
const getCountryCode = async () => {
const response = await axios.get(ip.getIPAddress)
setCountryCode(response?.data?.countryCode)

const resp = await liff.init({
liffId: '2006732958-EAK9vggN', // Use own liffId
})
console.info('Resp', resp)
console.log(liff.getAppLanguage())
console.log(liff.getVersion())
console.log('isInClient', liff.isInClient())
console.log(liff.isLoggedIn())
console.log(liff.getOS())
console.log(liff.getLineVersion())

const context = liff.getContext()
console.info('context', context)
console.info('isLoggedin', liff.isLoggedIn())
if (!liff.isLoggedIn()) {
liff.login()
}
}
getCountryCode()
}, [])
Expand Down
Loading

0 comments on commit b56f9b8

Please sign in to comment.