-
Notifications
You must be signed in to change notification settings - Fork 108
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 #559 from tonkeeper/release/3.4
Release 3.4
- Loading branch information
Showing
1,431 changed files
with
45,361 additions
and
35,347 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 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
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" | ||
} | ||
} |
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,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, | ||
}); |
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,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, | ||
}); |
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,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(); | ||
} | ||
} |
Oops, something went wrong.