Skip to content

Commit

Permalink
Merge pull request #559 from tonkeeper/release/3.4
Browse files Browse the repository at this point in the history
Release 3.4
  • Loading branch information
bogoslavskiy authored Sep 28, 2023
2 parents c399472 + 11b2dbc commit 7bab6bb
Show file tree
Hide file tree
Showing 1,431 changed files with 45,361 additions and 35,347 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ $ yarn start:mobile
$ yarn run:android
```

More information about android build in [android readme](android/README.md).
More information about android build in [android readme](packages/mobile/android/README.md).


## Adding icons
Expand Down Expand Up @@ -58,4 +58,4 @@ See https://www.gnu.org/licenses/ for a copy of this license.
See [LICENSE](LICENSE) file.


This project is tested with [Browserstack](https://browserstack.com).
This project is tested with [Browserstack](https://browserstack.com).
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
]
},
"scripts": {
"postinstall": "patch-package",
"pods": "cd packages && cd mobile && yarn pods",
"icons": "cd packages && cd mobile && yarn icons",
"codegen": "cd packages/@core-js && yarn codegen",
"start:mobile": "cd packages && cd mobile && yarn start",
"start:web": "cd packages && cd web && yarn start",
"run:ios": "cd packages && cd mobile && yarn ios",
Expand Down
3 changes: 0 additions & 3 deletions packages/@core-js/Dockerfile.apiV1

This file was deleted.

3 changes: 0 additions & 3 deletions packages/@core-js/Dockerfile.apiV2

This file was deleted.

19 changes: 10 additions & 9 deletions packages/@core-js/package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
{
"name": "@tonkeeper/core",
"version": "0.1.0",
"author": "Nikita Kuznetsov <[email protected]>",
"description": "Core features and state for tonkeeper web wallet",
"main": "src/index.ts",
"scripts": {
"build": "rm -fr dist && yarn generate:sdkV1 && yarn generate:sdkV2 && tsc",
"start": "tsc -w",
"generate:sdkV1": "rm -fr src/tonApiV1 && docker build -f Dockerfile.apiV1 . -t tonapisdk && docker run --rm --user=$(id -u):$(id -g) -v \"$PWD\":/local tonapisdk",
"generate:sdkV2": "rm -fr src/tonApiV2 && docker build -f Dockerfile.apiV2 . -t tonapisdk && docker run --rm --user=$(id -u):$(id -g) -v \"$PWD\":/local tonapisdk",
"build:pkg": "rm -fr dist && tsc"
"codegen": "node ./scripts/generate-tonapi && node ./scripts/generate-tronapi"
},
"license": "ISC",
"devDependencies": {
"@types/aes-js": "^3.1.1",
"swagger-typescript-api": "^13.0.0",
"typescript": "^4.9.4"
},
"dependencies": {
"@aws-crypto/sha256-js": "^3.0.0",
"@ethersproject/shims": "^5.7.0",
"@noble/ed25519": "1.7.3",
"aes-js": "3.1.2",
"bignumber.js": "^9.1.1",
"ton": "^13.3.0",
"ton-core": "^0.47.1",
"ethers": "^6.7.1",
"isomorphic-webcrypto": "^2.3.8",
"ton": "^13.5.0",
"ton-core": "^0.50.0",
"ton-crypto": "^3.2.0"
}
}
14 changes: 14 additions & 0 deletions packages/@core-js/scripts/generate-tonapi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { generateApi } = require('swagger-typescript-api');
const path = require('path');

generateApi({
url: 'https://raw.githubusercontent.com/tonkeeper/opentonapi/master/api/openapi.yml',
output: path.resolve(__dirname, '../src/TonAPI'),
name: 'TonAPIGenerated',
extractRequestParams: true,
apiClassName: 'TonAPIGenerated',
moduleNameIndex: 1,
extractEnums: true,
singleHttpClient: true,
unwrapResponseData: true,
});
14 changes: 14 additions & 0 deletions packages/@core-js/scripts/generate-tronapi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { generateApi } = require('swagger-typescript-api');
const path = require('path');

generateApi({
url: 'https://raw.githubusercontent.com/tonkeeper/gasless-tron-protocol/main/api/openapi.yml',
output: path.resolve(__dirname, '../src/TronAPI'),
name: 'TronAPIGenerated',
extractRequestParams: true,
apiClassName: 'TronAPIGenerated',
moduleNameIndex: 2,
extractEnums: true,
singleHttpClient: true,
unwrapResponseData: true,
});
142 changes: 142 additions & 0 deletions packages/@core-js/src/Activity/ActivityList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
import { ActivitySection, ActionItem, ActivityModel } from '../models/ActivityModel';
import { Storage } from '../declarations/Storage';
import { ActivityLoader } from './ActivityLoader';
import { Logger } from '../utils/Logger';
import { State } from '../utils/State';

type Cursors = {
tron: number | null;
ton: number | null;
};

type ActivityListState = {
sections: ActivitySection[];
error?: string | null;
isReloading: boolean;
isLoading: boolean;
hasMore: boolean;
};

export class ActivityList {
private refetchTimer: NodeJS.Timeout | null = null;
private readonly refetchTime = 15000;

private cursors: Cursors = { ton: null, tron: null };
private groups = {};

public state = new State<ActivityListState>({
isReloading: false,
isLoading: false,
hasMore: true,
sections: [],
error: null,
});

constructor(private activityLoader: ActivityLoader, private storage: Storage) {
this.state.persist({
storage: this.storage,
key: 'ActivityList',
partialize: ({ sections }) => ({ sections }),
rehydrated: ({ sections }) => {
sections.forEach((section) => {
this.activityLoader.setLoadedActions(section.data);
});
},
});
}

public async load(cursors?: Cursors) {
try {
this.state.set({ isLoading: true, error: null });

const ton = await this.activityLoader.loadTonActions({ cursor: cursors?.ton });
// const tronEvents = await this.fetchTronEvents({ cursor: cursors?.tron });

if (!cursors) {
this.groups = {};
}

const updatedGroups = ton.actions.reduce((groups, action, index) => {
if (index === 0 && action.event.in_progress) {
this.createTaskForReload();
}

const groupKey = ActivityModel.getGroupKey(action.event.timestamp);
if (!groups[groupKey]) {
groups[groupKey] = {
isFirst: index === 0,
timestamp: action.event.timestamp * 1000,
data: [],
};
}

groups[groupKey].data.push(action);

return groups;
}, this.groups);

this.groups = updatedGroups;

this.cursors = {
tron: null,
ton: ton.cursor ?? null,
};

this.state.set({
sections: Object.values(this.groups),
hasMore: Boolean(ton.cursor),
isLoading: false,
});
} catch (err) {
const message = `[ActivityList]: ${Logger.getErrorMessage(err)}`;
console.log(message);
this.state.set({
isLoading: false,
error: message,
});
}
}

public async loadMore() {
const { isLoading, hasMore, error } = this.state.data;
if (!isLoading && hasMore && error === null) {
return this.load(this.cursors);
}
}

public async rehydrate() {
return this.state.rehydrate();
}

public clear() {
this.groups = {};
}

public async reload() {
this.state.set({ isReloading: true });
await this.load();
this.state.set({ isReloading: false });
}

private createTaskForReload() {
this.clearReloadTask();
this.refetchTimer = setTimeout(() => {
this.reload();
this.refetchTimer = null;
}, this.refetchTime);
}

private clearReloadTask() {
if (this.refetchTimer !== null) {
clearTimeout(this.refetchTimer);
}
}

private sortByTimestamp(items: ActionItem[]) {
return items.sort((a, b) => b.event.timestamp - a.event.timestamp);
}

public preload() {
this.load();
}
}
Loading

0 comments on commit 7bab6bb

Please sign in to comment.