Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions src/utils/solong_adapter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import EventEmitter from 'eventemitter3';
import { PublicKey } from '@solana/web3.js';
import { notify } from "./notifications";

export class SolongAdapter extends EventEmitter {
_publicKey: any
_onProcess:boolean
constructor(providerUrl: string, network: string) {
super()
this._publicKey = null;
this._onProcess = false;
this.connect= this.connect.bind(this);
this.disconnect= this.disconnect.bind(this);
}

get publicKey() {
return this._publicKey;
}

async signTransaction(transaction: any) {
const trx = await (window as any).solong.signTransaction(transaction).catch(
() => {
throw {message:"Reject sign request!"}
}
);
return trx
}

connect() {
if (this._onProcess) {
return ;
}

if ((window as any).solong === undefined){
notify({
message: "Solong Error",
description: "Please install solong wallet from Chrome " ,
});
return;
}

this._onProcess = true;
console.log('solong helper select account');
(window as any).solong
.selectAccount()
.then((account: any) => {
this._publicKey = new PublicKey(account);
console.log('window solong select:', account, 'this:', this);
this.emit('connect', this._publicKey);
})
.catch(() => {
this.disconnect()
})
.finally(()=>{this._onProcess=false});
}

disconnect (){
if (this._publicKey) {
this._publicKey = null;
this.emit('disconnect');
}
}
}
9 changes: 8 additions & 1 deletion src/utils/wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { notify } from './notifications';
import { useConnectionConfig } from './connection';
import { useLocalStorageState } from './utils';
import { WalletContextValues } from './types';
import {SolongAdapter} from './solong_adapter'

export const WALLET_PROVIDERS = [
{name:'solong', url:'https://solongwallet.com/'},
{ name: 'sollet.io', url: 'https://www.sollet.io' },
];

Expand All @@ -25,7 +27,12 @@ export function WalletProvider({ children }) {
providerUrl = savedProviderUrl;
}

const wallet = useMemo(() => new Wallet(providerUrl, endpoint), [
const wallet :any = useMemo(() => {
if (providerUrl === 'https://solongwallet.com/') {
return new SolongAdapter(providerUrl, endpoint);
} else {
return new Wallet(providerUrl, endpoint)
}}, [
providerUrl,
endpoint,
]);
Expand Down