-
Notifications
You must be signed in to change notification settings - Fork 538
Add support for MathWallet extension #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
fd8ced2
mathwallet providerUrl
yuzhiyou1990 3f64fa4
mathwallet providerUrl
yuzhiyou1990 a158c69
mathwallet
yuzhiyou1990 6c46bc8
Merge branch 'master' of https://github.com/yuzhiyou1990/serum-dex-ui
yuzhiyou1990 8141612
fix
yuzhiyou1990 d6099c7
fix
yuzhiyou1990 163bf12
fix
yuzhiyou1990 7722975
fix
yuzhiyou1990 ddef26f
Merge branch 'master' into master
yuzhiyou1990 2110403
Delete yarn.lock
yuzhiyou1990 9fa53e5
Revert "Delete yarn.lock"
yuzhiyou1990 18abd5e
Update yarn.lock
yuzhiyou1990 ca8d2c8
Update yarn.lock
yuzhiyou1990 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| export * from './ledger'; | ||
| export * from './solong'; | ||
| export * from './phantom'; | ||
| export * from './math'; | ||
| export * from './types'; |
This file contains hidden or 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,91 @@ | ||
| import EventEmitter from 'eventemitter3'; | ||
| import { PublicKey, Transaction } from '@solana/web3.js'; | ||
| import { notify } from '../../utils/notifications'; | ||
| import { DEFAULT_PUBLIC_KEY, WalletAdapter } from '../types'; | ||
|
|
||
| export class MathWalletAdapter extends EventEmitter implements WalletAdapter { | ||
| _publicKey?: PublicKey; | ||
| _onProcess: boolean; | ||
| _connected: boolean; | ||
| constructor() { | ||
| super(); | ||
| this._onProcess = false; | ||
| this._connected = false; | ||
| this.connect = this.connect.bind(this); | ||
| } | ||
|
|
||
| get connected() { | ||
| return this._connected; | ||
| } | ||
|
|
||
| get autoApprove() { | ||
| return false; | ||
| } | ||
|
|
||
| public async signAllTransactions( | ||
| transactions: Transaction[], | ||
| ): Promise<Transaction[]> { | ||
| if (!this._provider) { | ||
| return transactions; | ||
| } | ||
|
|
||
| return this._provider.signAllTransactions(transactions); | ||
| } | ||
|
|
||
| private get _provider() { | ||
| if ((window as any)?.solana?.isMathWallet) { | ||
| return (window as any).solana; | ||
| } | ||
| return undefined; | ||
| } | ||
|
|
||
| get publicKey() { | ||
| return this._publicKey || DEFAULT_PUBLIC_KEY; | ||
| } | ||
|
|
||
| async signTransaction(transaction: Transaction) { | ||
| if (!this._provider) { | ||
| return transaction; | ||
| } | ||
|
|
||
| return this._provider.signTransaction(transaction); | ||
| } | ||
|
|
||
| connect() { | ||
| if (this._onProcess) { | ||
| return; | ||
| } | ||
|
|
||
| if (!this._provider) { | ||
| window.open('https://mathwallet.org/', '_blank'); | ||
| notify({ | ||
| message: 'Math Wallet Error', | ||
| description: 'Please install mathwallet', | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| this._onProcess = true; | ||
| this._provider | ||
| .getAccount() | ||
| .then((account: any) => { | ||
| this._publicKey = new PublicKey(account); | ||
| this._connected = true; | ||
| this.emit('connect', this._publicKey); | ||
| }) | ||
| .catch(() => { | ||
| this.disconnect(); | ||
| }) | ||
| .finally(() => { | ||
| this._onProcess = false; | ||
| }); | ||
| } | ||
|
|
||
| disconnect() { | ||
| if (this._publicKey) { | ||
| this._publicKey = undefined; | ||
| this._connected = false; | ||
| this.emit('disconnect'); | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting an error when calling
getAccount, is this supposed to begetAccounts()?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The getAccount method is correct, update MathWallet extension to v2.6.4.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed v2.6.4 works