mirror of https://github.com/certusone/oyster.git
feat: torus
This commit is contained in:
parent
2b6a4b5016
commit
96dc5e08cc
|
@ -2,13 +2,17 @@ import React from 'react';
|
||||||
import { Button, Select } from 'antd';
|
import { Button, Select } from 'antd';
|
||||||
import { useWallet } from '../../contexts/wallet';
|
import { useWallet } from '../../contexts/wallet';
|
||||||
import { ENDPOINTS, useConnectionConfig } from '../../contexts/connection';
|
import { ENDPOINTS, useConnectionConfig } from '../../contexts/connection';
|
||||||
|
import { shortenAddress } from '../../utils';
|
||||||
|
import {
|
||||||
|
CopyOutlined
|
||||||
|
} from '@ant-design/icons';
|
||||||
|
|
||||||
export const Settings = ({
|
export const Settings = ({
|
||||||
additionalSettings,
|
additionalSettings,
|
||||||
}: {
|
}: {
|
||||||
additionalSettings?: JSX.Element;
|
additionalSettings?: JSX.Element;
|
||||||
}) => {
|
}) => {
|
||||||
const { connected, disconnect, select } = useWallet();
|
const { connected, disconnect, select, wallet } = useWallet();
|
||||||
const { endpoint, setEndpoint } = useConnectionConfig();
|
const { endpoint, setEndpoint } = useConnectionConfig();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -29,6 +33,12 @@ export const Settings = ({
|
||||||
{connected && (
|
{connected && (
|
||||||
<>
|
<>
|
||||||
<span>Wallet:</span>
|
<span>Wallet:</span>
|
||||||
|
{wallet?.publicKey && (<Button
|
||||||
|
style={{ marginBottom: 5 }} onClick={() => navigator.clipboard.writeText(wallet.publicKey?.toBase58() || '')}>
|
||||||
|
<CopyOutlined />
|
||||||
|
{shortenAddress(wallet?.publicKey.toBase58())}
|
||||||
|
</Button>)}
|
||||||
|
|
||||||
<Button onClick={select}
|
<Button onClick={select}
|
||||||
style={{ marginBottom: 5 }}>
|
style={{ marginBottom: 5 }}>
|
||||||
Change
|
Change
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import EventEmitter from "eventemitter3"
|
import EventEmitter from "eventemitter3"
|
||||||
import solanaWeb3 from "@solana/web3.js"
|
import { Account, PublicKey, Transaction } from "@solana/web3.js"
|
||||||
import { Account, PublicKey, Transaction, Connection } from "@solana/web3.js"
|
|
||||||
import { WalletAdapter } from "@solana/wallet-base"
|
import { WalletAdapter } from "@solana/wallet-base"
|
||||||
import Torus from "@toruslabs/torus-embed"
|
|
||||||
import OpenLogin from "@toruslabs/openlogin"
|
import OpenLogin from "@toruslabs/openlogin"
|
||||||
import { getED25519Key } from "@toruslabs/openlogin-ed25519"
|
import { getED25519Key } from "@toruslabs/openlogin-ed25519"
|
||||||
|
|
||||||
|
@ -12,7 +10,6 @@ const getSolanaPrivateKey = (openloginKey: string)=>{
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TorusWalletAdapter extends EventEmitter implements WalletAdapter {
|
export class TorusWalletAdapter extends EventEmitter implements WalletAdapter {
|
||||||
// _provider: Torus | undefined;
|
|
||||||
_provider: OpenLogin | undefined;
|
_provider: OpenLogin | undefined;
|
||||||
endpoint: string;
|
endpoint: string;
|
||||||
providerUrl: string;
|
providerUrl: string;
|
||||||
|
@ -20,8 +17,6 @@ export class TorusWalletAdapter extends EventEmitter implements WalletAdapter {
|
||||||
image: string = '';
|
image: string = '';
|
||||||
name: string = '';
|
name: string = '';
|
||||||
|
|
||||||
autoConnect = true;
|
|
||||||
|
|
||||||
constructor(providerUrl: string, endpoint: string) {
|
constructor(providerUrl: string, endpoint: string) {
|
||||||
super()
|
super()
|
||||||
this.connect = this.connect.bind(this)
|
this.connect = this.connect.bind(this)
|
||||||
|
@ -73,16 +68,14 @@ export class TorusWalletAdapter extends EventEmitter implements WalletAdapter {
|
||||||
const { privKey } = await this._provider.login();
|
const { privKey } = await this._provider.login();
|
||||||
const secretKey = getSolanaPrivateKey(privKey);
|
const secretKey = getSolanaPrivateKey(privKey);
|
||||||
this.account = new Account(secretKey);
|
this.account = new Account(secretKey);
|
||||||
} catch {
|
} catch(ex) {
|
||||||
//
|
console.error('login failed', ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.name = this._provider?.state.store.get('name');;
|
this.name = this._provider?.state.store.get('name');;
|
||||||
this.image = this._provider?.state.store.get('profileImage');;
|
this.image = this._provider?.state.store.get('profileImage');;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
this.emit("connect");
|
this.emit("connect");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue