Skip to content

Commit

Permalink
chore: ci is green (#3)
Browse files Browse the repository at this point in the history
* chore: ci is green

* fixes

* lint
  • Loading branch information
vivalaakam authored May 22, 2023
1 parent 3eba784 commit ee60b55
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 76 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/ci-green.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: CI green

on:
push:
branches: [main]
pull_request:
branches: [main]
merge_group:
types: [checks_requested]

concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

env:
NODE_VERSION: '16.17.1'

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Setup node
uses: actions/[email protected]
with:
node-version: ${{ env.NODE_VERSION }}
cache: yarn
- uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Run linters
run: |
yarn lint
yarn typescript:check
yarn prettier:check
yarn test
ci-pass:
name: CI is green
runs-on: ubuntu-latest
needs:
- test

steps:
- run: exit 0
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"build": "tsc",
"format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
"lint": "tslint -p tsconfig.json",
"typescript:check": "tsc",
"prettier:check": "prettier --check ./src",
"prettier:format": "prettier --write \"src/**/*.ts\"",
"typedoc": "typedoc"
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/commands/get-version.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import TransportBLE from '@ledgerhq/react-native-hw-transport-ble';

export const getVersion = async (transport: TransportBLE) => {
return await transport.send(0xe0, 0x01, 0x00, 0x00)
}
return await transport.send(0xe0, 0x01, 0x00, 0x00);
};
12 changes: 6 additions & 6 deletions src/commands/list-apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type App = {
hashCodeData: string;
blocks: number;
flags: number;
}
};

export const listApps = async (transport: TransportBLE) => {
const payload = await transport.send(0xe0, 0xde, 0, 0);
Expand All @@ -16,7 +16,7 @@ export const listApps = async (transport: TransportBLE) => {
// more than the status bytes
while (data.length > 2) {
if (payload[0] !== 0x01) {
throw new Error("unknown listApps format");
throw new Error('unknown listApps format');
}

let i = 1;
Expand All @@ -28,18 +28,18 @@ export const listApps = async (transport: TransportBLE) => {
i += 2;
const flags = data.readUInt16BE(i);
i += 2;
const hashCodeData = data.slice(i, i + 32).toString("hex");
const hashCodeData = data.slice(i, i + 32).toString('hex');
i += 32;
const hash = data.slice(i, i + 32).toString("hex");
const hash = data.slice(i, i + 32).toString('hex');
i += 32;
const nameLength = data[i];
i++;

if (length !== nameLength + 70) {
throw new Error("invalid listApps length data");
throw new Error('invalid listApps length data');
}

const name = data.slice(i, i + nameLength).toString("ascii");
const name = data.slice(i, i + nameLength).toString('ascii');
i += nameLength;
apps.push({
name,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/quit-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import TransportBLE from '@ledgerhq/react-native-hw-transport-ble';

export const quitApp = async (transport: TransportBLE) => {
await transport.send(0xb0, 0xa7, 0x00, 0x00);
}
};
8 changes: 3 additions & 5 deletions src/commands/suggest-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ export const suggestApp = async (
await openApp(transport, name);
}
} catch (err) {
console.error('suggestApp', err);

//@ts-ignore
if(err instanceof Error && !!err.statusCode){
throw err
// @ts-ignore
if (err instanceof Error && !!err.statusCode) {
throw err;
}
}
};
4 changes: 2 additions & 2 deletions src/get-ble-manager.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {BleManager} from 'react-native-ble-plx';

let bleManager: BleManager | null = null
let bleManager: BleManager | null = null;

export function getBleManager(): BleManager {
if (!bleManager) {
bleManager = new BleManager();
}

return bleManager!
return bleManager!;
}
11 changes: 4 additions & 7 deletions src/get-device-connection.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {State} from 'react-native-ble-plx';
import {getBleManager} from './get-ble-manager';

const cache = new Map()
const cache = new Map();

const connectOptions = {
requestMTU: 156,
Expand All @@ -16,12 +16,9 @@ export async function getDeviceConnection(deviceId: string) {
throw new Error(`not_connected ${state}`);
}
if (!cache.has(deviceId)) {
const result = await bleManager.connectToDevice(
deviceId,
connectOptions,
);
const result = await bleManager.connectToDevice(deviceId, connectOptions);

if(result) {
if (result) {
cache.set(deviceId, result);
}
}
Expand All @@ -38,5 +35,5 @@ export async function getDeviceConnection(deviceId: string) {
await device.connect();
}

return device
return device;
}
Loading

0 comments on commit ee60b55

Please sign in to comment.