Skip to content

Commit

Permalink
Merge pull request #206 from thepower/feat/get_node_settins_current
Browse files Browse the repository at this point in the history
add chain setting current api method
  • Loading branch information
jackkru69 authored Dec 24, 2024
2 parents a3a7bf6 + c2f97b8 commit 6062b70
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-islands-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@thepowereco/tssdk': patch
---

add chain setting current api method
9 changes: 9 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"mode": "pre",
"tag": "canary",
"initialVersions": {
"@thepowereco/cli": "1.12.15",
"@thepowereco/tssdk": "2.2.12"
},
"changesets": []
}
1 change: 1 addition & 0 deletions packages/tssdk/src/helpers/network.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export enum ChainAction {
GET_WALLET = 'GET_WALLET',
GET_WALLET_SEQUENCE = 'GET_SEQUENCE',
GET_NODE_SETTINGS = 'GET_NODE_SETTINGS',
GET_NODE_SETTINGS_CURRENT = 'GET_NODE_SETTINGS_CURRENT',
CREATE_TRANSACTION = 'CREATE_TRANSACTION',
EXECUTE_CALL = 'EXECUTE_CALL',
GET_MY_CHAIN = 'GET_MY_CHAIN',
Expand Down
3 changes: 3 additions & 0 deletions packages/tssdk/src/helpers/network.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ export const transformResponse = (response: any, kind: ChainAction, requestParam

case ChainAction.GET_NODE_SETTINGS:
return response.settings

case ChainAction.GET_NODE_SETTINGS_CURRENT:
return response.settings
default:
return response
}
Expand Down
16 changes: 10 additions & 6 deletions packages/tssdk/src/libs/network/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class NetworkApi {
}

public async getFeeSettings() {
const settings = await this.askBlockchainTo(ChainAction.GET_NODE_SETTINGS, {})
const settings = await this.askBlockchainTo(ChainAction.GET_NODE_SETTINGS_CURRENT, {})
return this.calculateFeeSettings(settings)
}

Expand Down Expand Up @@ -329,7 +329,7 @@ export class NetworkApi {
}

private calculateFeeSettings(settings: any) {
let result = settings.current
let result = settings
let feeCur = ''

if (result.fee) {
Expand Down Expand Up @@ -467,7 +467,7 @@ export class NetworkApi {
}

public async getNodeSettings() {
return this.askBlockchainTo(ChainAction.GET_NODE_SETTINGS, {})
return this.askBlockchainTo(ChainAction.GET_NODE_SETTINGS_CURRENT, {})
}

public async createTransaction(data: { tx: string }) {
Expand Down Expand Up @@ -594,6 +594,10 @@ export class NetworkApi {
actionUrl = '/settings'
break

case ChainAction.GET_NODE_SETTINGS_CURRENT:
actionUrl = '/settings/current'
break

case ChainAction.GET_SC_CODE:
requestParams.responseType = 'arraybuffer'
requestParams.url = `${parameters.address}/code`
Expand Down Expand Up @@ -629,15 +633,15 @@ export class NetworkApi {
}

private async loadFeeGasSettingsAndDecimals() {
const settings = await this.askBlockchainTo(ChainAction.GET_NODE_SETTINGS, {})
const settings = await this.askBlockchainTo(ChainAction.GET_NODE_SETTINGS_CURRENT, {})
this._feeSettings = this.calculateFeeSettings(settings)
this._gasSettings = this.calculateGasSettings(settings)

this._decimals = settings?.current?.decimals || { SK: 9 }
this._decimals = settings?.decimals || { SK: 9 }
}

private calculateGasSettings(settings: any) {
let result = settings.current
let result = settings
let gasCur

if (result.gas) {
Expand Down
2 changes: 1 addition & 1 deletion packages/tssdk/src/libs/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class WalletApi {

const settings = await networkApi.getNodeSettings()

const derivationPath = `${DERIVATION_PATH_BASE}/${COIN}'/0'/${settings.current.allocblock.block}'/${settings.current.allocblock.group}'`
const derivationPath = `${DERIVATION_PATH_BASE}/${COIN}'/0'/${settings.allocblock.block}'/${settings.allocblock.group}'`

const keyPair = await CryptoApi.generateKeyPairFromSeedPhrase(seed, derivationPath)

Expand Down

0 comments on commit 6062b70

Please sign in to comment.