-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial implementation of custom client * Allowed build from Windows * Fixed problem with instance metadata not being displayed in the interface * Fixing problem with unreliable clipboard copy * Hiding clients that failed to initialise from the UI * Added VS code auto-formatting * Pull request feedback Also made the clipboard code more robust
- Loading branch information
Showing
16 changed files
with
511 additions
and
39 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"editor.formatOnSave": true, | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll.eslint": true | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import Algod, { getAlgodClient } from '../../algod' | ||
import BaseClient from '../base' | ||
import { DEFAULT_NETWORK, PROVIDER_ID } from '../../constants' | ||
import { debugLog } from '../../utils/debugLog' | ||
import { ICON } from './constants' | ||
import type _algosdk from 'algosdk' | ||
import type { Network } from '../../types/node' | ||
import type { InitParams } from '../../types/providers' | ||
import type { Metadata, Wallet } from '../../types/wallet' | ||
import type { CustomProvider, CustomWalletClientConstructor } from './types' | ||
|
||
class CustomWalletClient extends BaseClient { | ||
network: Network | ||
providerProxy: CustomProvider | ||
|
||
static metadata: Metadata = { | ||
id: PROVIDER_ID.CUSTOM, | ||
icon: ICON, | ||
isWalletConnect: false, | ||
name: 'Custom' | ||
} | ||
|
||
constructor({ | ||
providerProxy, | ||
metadata, | ||
algosdk, | ||
algodClient, | ||
network | ||
}: CustomWalletClientConstructor) { | ||
super(metadata, algosdk, algodClient) | ||
|
||
this.providerProxy = providerProxy | ||
this.network = network | ||
} | ||
|
||
static async init({ | ||
clientOptions, | ||
algodOptions, | ||
algosdkStatic, | ||
network = DEFAULT_NETWORK | ||
}: InitParams<PROVIDER_ID.CUSTOM>): Promise<BaseClient | null> { | ||
try { | ||
debugLog(`${PROVIDER_ID.CUSTOM.toUpperCase()} initializing...`) | ||
|
||
if (!clientOptions) { | ||
throw new Error(`Attempt to create custom wallet with no provider specified.`) | ||
} | ||
|
||
const algosdk = algosdkStatic || (await Algod.init(algodOptions)).algosdk | ||
const algodClient = getAlgodClient(algosdk, algodOptions) | ||
|
||
try { | ||
return new CustomWalletClient({ | ||
providerProxy: clientOptions.getProvider({ | ||
algod: algodClient, | ||
algosdkStatic: algosdk, | ||
network | ||
}), | ||
metadata: { | ||
...CustomWalletClient.metadata, | ||
name: clientOptions.name, | ||
icon: clientOptions.icon ?? CustomWalletClient.metadata.icon | ||
}, | ||
algodClient, | ||
algosdk, | ||
network | ||
}) | ||
} finally { | ||
debugLog(`${PROVIDER_ID.CUSTOM.toUpperCase()} initialized`, '✅') | ||
} | ||
} catch (e) { | ||
console.error('Error initializing...', e) | ||
return null | ||
} | ||
} | ||
|
||
async connect(): Promise<Wallet> { | ||
return await this.providerProxy.connect(this.metadata) | ||
} | ||
|
||
async disconnect() { | ||
await this.providerProxy.disconnect() | ||
} | ||
|
||
async reconnect(): Promise<Wallet | null> { | ||
return await this.providerProxy.reconnect(this.metadata) | ||
} | ||
|
||
async signTransactions( | ||
connectedAccounts: string[], | ||
txnGroups: Uint8Array[] | Uint8Array[][], | ||
indexesToSign?: number[], | ||
returnGroup = true | ||
) { | ||
return await this.providerProxy.signTransactions( | ||
connectedAccounts, | ||
txnGroups, | ||
indexesToSign, | ||
returnGroup | ||
) | ||
} | ||
} | ||
|
||
export default CustomWalletClient |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const ICON = | ||
"data:image/svg+xml,%3Csvg fill='%23000000' width='800px' height='800px' viewBox='0 0 24 24' id='wallet' data-name='Flat Line' xmlns='http://www.w3.org/2000/svg' class='icon flat-line'%3E%3Cpath id='secondary' d='M16,12h5V8H5A2,2,0,0,1,3,6V19a1,1,0,0,0,1,1H20a1,1,0,0,0,1-1V16H16a1,1,0,0,1-1-1V13A1,1,0,0,1,16,12Z' style='fill: rgb(44, 169, 188); stroke-width: 2;'%3E%3C/path%3E%3Cpath id='primary' d='M19,4H5A2,2,0,0,0,3,6H3A2,2,0,0,0,5,8H21' style='fill: none; stroke: rgb(0, 0, 0); stroke-linecap: round; stroke-linejoin: round; stroke-width: 2;'%3E%3C/path%3E%3Cpath id='primary-2' data-name='primary' d='M21,8V19a1,1,0,0,1-1,1H4a1,1,0,0,1-1-1V6A2,2,0,0,0,5,8Zm0,4H16a1,1,0,0,0-1,1v2a1,1,0,0,0,1,1h5Z' style='fill: none; stroke: rgb(0, 0, 0); stroke-linecap: round; stroke-linejoin: round; stroke-width: 2;'%3E%3C/path%3E%3C/svg%3E" |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import custom from './client' | ||
|
||
export default custom |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type algosdk from 'algosdk' | ||
import type { Network } from '../../types/node' | ||
import type { Metadata, Wallet } from '../../types/wallet' | ||
|
||
export type CustomOptions = { | ||
name: string | ||
icon?: string | ||
getProvider: (params: { | ||
network?: Network | ||
algod?: algosdk.Algodv2 | ||
algosdkStatic?: typeof algosdk | ||
}) => CustomProvider | ||
} | ||
|
||
export type CustomProvider = { | ||
connect(metadata: Metadata): Promise<Wallet> | ||
disconnect(): Promise<void> | ||
reconnect(metadata: Metadata): Promise<Wallet | null> | ||
signTransactions( | ||
connectedAccounts: string[], | ||
txnGroups: Uint8Array[] | Uint8Array[][], | ||
indexesToSign?: number[], | ||
returnGroup?: boolean | ||
): Promise<Uint8Array[]> | ||
} | ||
|
||
export type CustomWalletClientConstructor = { | ||
providerProxy: CustomProvider | ||
metadata: Metadata | ||
algosdk: typeof algosdk | ||
algodClient: algosdk.Algodv2 | ||
network: Network | ||
} |
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
Oops, something went wrong.