-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from getsumer/mmo/feat-wallet-observer
Mmo/feat wallet observer
- Loading branch information
Showing
21 changed files
with
170 additions
and
490 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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 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 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 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,3 +1 @@ | ||
export * from './ContractError' | ||
export * from './ProviderError' | ||
export * from './Transaction' |
This file was deleted.
Oops, something went wrong.
This file contains 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,12 +1,55 @@ | ||
import { Target } from './Target' | ||
import { Target, TargetExecution } from './Target' | ||
import { Observer } from './Observer' | ||
import { NotifyService } from '../services' | ||
import bowser, { Parser } from 'bowser' | ||
|
||
enum Wallet { | ||
BRAVEWALLET = 'isBraveWallet', | ||
COINBASE = 'isCoinbaseWallet', | ||
METAMASK = 'isMetaMask', | ||
} | ||
export abstract class SumerObserver implements Observer { | ||
private readonly NULL_ADDRESS = '0x0000000000000000000000000000000000000000' | ||
protected readonly notifyService: NotifyService | ||
|
||
constructor(notifyService: NotifyService) { | ||
this.notifyService = notifyService | ||
} | ||
|
||
public abstract inspect(_target: Target): Promise<void> | ||
|
||
protected getWallet(_executionTarget: Record<string, string | object>): string | undefined { | ||
const wallets = { | ||
[Wallet.COINBASE]: { addressKey: '_addresses', nameKey: 'Coinbase' }, | ||
[Wallet.BRAVEWALLET]: { addressKey: 'selectedAddress', nameKey: 'Brave' }, | ||
[Wallet.METAMASK]: { addressKey: 'selectedAddress', nameKey: 'Metamask' }, | ||
} | ||
|
||
for (const [walletKey, { addressKey, nameKey }] of Object.entries(wallets)) { | ||
if ( | ||
_executionTarget?.[walletKey] && | ||
typeof _executionTarget[walletKey] === 'boolean' && | ||
_executionTarget[addressKey] | ||
) { | ||
return nameKey | ||
} | ||
} | ||
return undefined | ||
} | ||
protected meta(): Parser.ParsedResult | Record<string, string> { | ||
if (window?.navigator?.userAgent) { | ||
return bowser.parse(window.navigator.userAgent) | ||
} | ||
return {} | ||
} | ||
|
||
protected getAddress(execution: TargetExecution): string { | ||
if (execution.target.selectedAddress) { | ||
return execution.target.selectedAddress.toString() | ||
} | ||
if (execution.target._addresses && execution.target._addresses[0]) { | ||
return execution.target._addresses[0].toString() | ||
} | ||
return this.NULL_ADDRESS | ||
} | ||
} |
Oops, something went wrong.