Skip to content

Commit

Permalink
Merge pull request #418 from shapeshift/return-actual-types
Browse files Browse the repository at this point in the history
return actual types from adapter.pairDevice()
  • Loading branch information
mrnerdhair authored Mar 22, 2022
2 parents 3069379 + e836c01 commit 1a6fe61
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions packages/hdwallet-keepkey/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class Adapter<DelegateType extends AdapterDelegate<any>> {
return await this.delegate.getTransportDelegate(device);
}

async pairDevice(serialNumber?: string, tryDebugLink?: boolean): Promise<core.HDWallet> {
async pairDevice(serialNumber?: string, tryDebugLink?: boolean): Promise<KeepKeyHDWallet> {
const device = await this.getDevice(serialNumber);
if (!device)
throw new Error(
Expand All @@ -153,8 +153,8 @@ export class Adapter<DelegateType extends AdapterDelegate<any>> {
return this.pairRawDevice(device, tryDebugLink);
}

async pairRawDevice(device: DeviceType<DelegateType>, tryDebugLink?: boolean): Promise<core.HDWallet> {
async pairRawDevice(device: DeviceType<DelegateType>, tryDebugLink?: boolean): Promise<KeepKeyHDWallet> {
await this.initialize([device], tryDebugLink, true);
return core.mustBeDefined(this.keyring.get((await this.inspectDevice(device)).serialNumber));
return core.mustBeDefined(this.keyring.get<KeepKeyHDWallet>((await this.inspectDevice(device)).serialNumber));
}
}
10 changes: 5 additions & 5 deletions packages/hdwallet-ledger-webhid/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class WebHIDLedgerAdapter {
try {
await this.initialize(e.device);
this.keyring.emit(["Ledger", e.device.productName ?? "", core.Events.CONNECT], MOCK_SERIAL_NUMBER);
} catch (error) {
} catch (error: any) {
this.keyring.emit(
["Ledger", e.device.productName ?? "", core.Events.FAILURE],
[MOCK_SERIAL_NUMBER, { message: { code: error.type, ...error } }]
Expand Down Expand Up @@ -60,8 +60,8 @@ export class WebHIDLedgerAdapter {
}, APP_NAVIGATION_DELAY);
}

public get(): core.HDWallet {
return core.mustBeDefined(this.keyring.get(MOCK_SERIAL_NUMBER));
public get(): ledger.LedgerHDWallet {
return core.mustBeDefined(this.keyring.get<ledger.LedgerHDWallet>(MOCK_SERIAL_NUMBER));
}

// without unique device identifiers, we should only ever have one HID ledger device on the keyring at a time
Expand All @@ -81,13 +81,13 @@ export class WebHIDLedgerAdapter {
return Object.keys(this.keyring.wallets).length;
}

public async pairDevice(): Promise<core.HDWallet> {
public async pairDevice(): Promise<ledger.LedgerHDWallet> {
const ledgerTransport = await getTransport();

const device = ledgerTransport.device;

await this.initialize(device);

return core.mustBeDefined(this.keyring.get(MOCK_SERIAL_NUMBER));
return core.mustBeDefined(this.keyring.get<ledger.LedgerHDWallet>(MOCK_SERIAL_NUMBER));
}
}
10 changes: 5 additions & 5 deletions packages/hdwallet-ledger-webusb/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class WebUSBLedgerAdapter {
try {
await this.initialize(e.device);
this.keyring.emit([e.device.manufacturerName ?? "", e.device.productName ?? "", core.Events.CONNECT], e.device.serialNumber);
} catch (error) {
} catch (error: any) {
this.keyring.emit(
[e.device.manufacturerName ?? "", e.device.productName ?? "", core.Events.FAILURE],
[e.device.serialNumber, { message: { code: error.type, ...error } }]
Expand Down Expand Up @@ -60,8 +60,8 @@ export class WebUSBLedgerAdapter {
}, APP_NAVIGATION_DELAY);
}

public get(device: USBDevice): core.HDWallet {
return core.mustBeDefined(this.keyring.get(device.serialNumber));
public get(device: USBDevice): ledger.LedgerHDWallet {
return core.mustBeDefined(this.keyring.get<ledger.LedgerHDWallet>(device.serialNumber));
}

// without unique device identifiers, we should only ever have one ledger device on the keyring at a time
Expand All @@ -81,13 +81,13 @@ export class WebUSBLedgerAdapter {
return Object.keys(this.keyring.wallets).length;
}

public async pairDevice(): Promise<core.HDWallet> {
public async pairDevice(): Promise<ledger.LedgerHDWallet> {
const ledgerTransport = await getTransport();

const device = ledgerTransport.device;

await this.initialize(device);

return core.mustBeDefined(this.keyring.get(device.serialNumber));
return core.mustBeDefined(this.keyring.get<ledger.LedgerHDWallet>(device.serialNumber));
}
}
2 changes: 1 addition & 1 deletion packages/hdwallet-metamask/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class MetaMaskAdapter {
return Object.keys(this.keyring.wallets).length;
}

public async pairDevice(): Promise<core.HDWallet> {
public async pairDevice(): Promise<MetaMaskHDWallet> {
const provider: any = await detectEthereumProvider({ mustBeMetaMask: true, silent: false, timeout: 3000 });
if (!provider) {
const onboarding = new MetaMaskOnboarding();
Expand Down
2 changes: 1 addition & 1 deletion packages/hdwallet-native/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class NativeAdapter {
return 0;
}

async pairDevice(deviceId: string): Promise<core.HDWallet | null> {
async pairDevice(deviceId: string): Promise<native.NativeHDWallet | null> {
let wallet: core.HDWallet | null = this.keyring.get(deviceId);
if (!wallet && deviceId) {
// If a wallet with that ID hasn't been added to the keychain, then create it
Expand Down
4 changes: 2 additions & 2 deletions packages/hdwallet-portis/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class PortisAdapter {
return Object.keys(this.keyring.wallets).length;
}

public async pairDevice(): Promise<core.HDWallet> {
public async pairDevice(): Promise<PortisHDWallet> {
try {
const wallet = await this.pairPortisDevice();
this.portis.onActiveWalletChanged(async (wallAddr: string) => {
Expand Down Expand Up @@ -58,7 +58,7 @@ export class PortisAdapter {
}
}

private async pairPortisDevice(): Promise<core.HDWallet> {
private async pairPortisDevice(): Promise<PortisHDWallet> {
const Portis = (await import("@portis/web3")).default;
this.portis = new Portis(this.portisAppId, "mainnet");
const wallet = new PortisHDWallet(this.portis);
Expand Down
2 changes: 1 addition & 1 deletion packages/hdwallet-trezor-connect/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class TrezorAdapter {
return Object.keys(this.keyring.wallets).length;
}

public async pairDevice(): Promise<core.HDWallet> {
public async pairDevice(): Promise<trezor.TrezorHDWallet> {
const init = await _initialization;
if (!init) throw new Error("Could not pair Trezor: TrezorConnect not initialized");

Expand Down
2 changes: 1 addition & 1 deletion packages/hdwallet-xdefi/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class XDeFiAdapter {
return Object.keys(this.keyring.wallets).length;
}

public async pairDevice(): Promise<core.HDWallet> {
public async pairDevice(): Promise<XDeFiHDWallet> {
const provider: any = (globalThis as any).xfi?.ethereum;
if (!provider) {
throw new Error("XDeFi provider not found");
Expand Down

1 comment on commit 1a6fe61

@vercel
Copy link

@vercel vercel bot commented on 1a6fe61 Mar 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

Please sign in to comment.