feat: torus

This commit is contained in:
bartosz-lipinski 2021-04-21 18:44:18 -05:00
parent 2b6a4b5016
commit 96dc5e08cc
2 changed files with 14 additions and 11 deletions

View File

@ -2,13 +2,17 @@ import React from 'react';
import { Button, Select } from 'antd';
import { useWallet } from '../../contexts/wallet';
import { ENDPOINTS, useConnectionConfig } from '../../contexts/connection';
import { shortenAddress } from '../../utils';
import {
CopyOutlined
} from '@ant-design/icons';
export const Settings = ({
additionalSettings,
}: {
additionalSettings?: JSX.Element;
}) => {
const { connected, disconnect, select } = useWallet();
const { connected, disconnect, select, wallet } = useWallet();
const { endpoint, setEndpoint } = useConnectionConfig();
return (
@ -29,6 +33,12 @@ export const Settings = ({
{connected && (
<>
<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}
style={{ marginBottom: 5 }}>
Change

View File

@ -1,8 +1,6 @@
import EventEmitter from "eventemitter3"
import solanaWeb3 from "@solana/web3.js"
import { Account, PublicKey, Transaction, Connection } from "@solana/web3.js"
import { Account, PublicKey, Transaction } from "@solana/web3.js"
import { WalletAdapter } from "@solana/wallet-base"
import Torus from "@toruslabs/torus-embed"
import OpenLogin from "@toruslabs/openlogin"
import { getED25519Key } from "@toruslabs/openlogin-ed25519"
@ -12,7 +10,6 @@ const getSolanaPrivateKey = (openloginKey: string)=>{
}
export class TorusWalletAdapter extends EventEmitter implements WalletAdapter {
// _provider: Torus | undefined;
_provider: OpenLogin | undefined;
endpoint: string;
providerUrl: string;
@ -20,8 +17,6 @@ export class TorusWalletAdapter extends EventEmitter implements WalletAdapter {
image: string = '';
name: string = '';
autoConnect = true;
constructor(providerUrl: string, endpoint: string) {
super()
this.connect = this.connect.bind(this)
@ -73,16 +68,14 @@ export class TorusWalletAdapter extends EventEmitter implements WalletAdapter {
const { privKey } = await this._provider.login();
const secretKey = getSolanaPrivateKey(privKey);
this.account = new Account(secretKey);
} catch {
//
} catch(ex) {
console.error('login failed', ex);
}
}
this.name = this._provider?.state.store.get('name');;
this.image = this._provider?.state.store.get('profileImage');;
this.emit("connect");
}