Skip to content

Commit

Permalink
fix: earn protocol detail crash OK-32584 (#5904)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwoktung authored Sep 24, 2024
1 parent 83ff1ff commit 8ca12ac
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
15 changes: 15 additions & 0 deletions packages/kit-bg/src/services/ServiceStaking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,21 @@ class ServiceStaking extends ServiceBase {
});
return resp.data.data.list;
}

@backgroundMethod()
async buildEarnTx({
accountId,
networkId,
tx,
}: {
accountId: string;
networkId: string;
tx: IStakeTxResponse;
}) {
const vault = await vaultFactory.getVault({ networkId, accountId });
const encodedTx = await vault.buildStakeEncodedTx(tx as any);
return encodedTx;
}
}

export default ServiceStaking;
24 changes: 17 additions & 7 deletions packages/kit/src/views/Staking/hooks/useUniversalHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useCallback } from 'react';

import backgroundApiProxy from '@onekeyhq/kit/src/background/instance/backgroundApiProxy';
import { useSendConfirm } from '@onekeyhq/kit/src/hooks/useSendConfirm';
import { vaultFactory } from '@onekeyhq/kit-bg/src/vaults/factory';
import { type IModalSendParamList } from '@onekeyhq/shared/src/routes';
import networkUtils from '@onekeyhq/shared/src/utils/networkUtils';
import { EAccountSelectorSceneName } from '@onekeyhq/shared/types';
Expand Down Expand Up @@ -47,8 +46,13 @@ export function useUniversalStake({
term,
provider,
});
const vault = await vaultFactory.getVault({ networkId, accountId });
const encodedTx = await vault.buildStakeEncodedTx(stakeTx);

const encodedTx = await backgroundApiProxy.serviceStaking.buildEarnTx({
networkId,
accountId,
tx: stakeTx,
});

let useFeeInTx;
let feeInfoEditable;
if (networkUtils.isBTCNetwork(networkId)) {
Expand Down Expand Up @@ -153,8 +157,11 @@ export function useUniversalWithdraw({
provider,
});
}
const vault = await vaultFactory.getVault({ networkId, accountId });
const encodedTx = await vault.buildStakeEncodedTx(stakeTx as any);
const encodedTx = await backgroundApiProxy.serviceStaking.buildEarnTx({
networkId,
accountId,
tx: stakeTx,
});
await navigationToSendConfirm({
encodedTx,
stakingInfo,
Expand Down Expand Up @@ -219,8 +226,11 @@ export function useUniversalClaim({
amount,
identity,
});
const vault = await vaultFactory.getVault({ networkId, accountId });
const encodedTx = await vault.buildStakeEncodedTx(stakeTx as any);
const encodedTx = await backgroundApiProxy.serviceStaking.buildEarnTx({
networkId,
accountId,
tx: stakeTx,
});
await navigationToSendConfirm({
encodedTx,
stakingInfo,
Expand Down

0 comments on commit 8ca12ac

Please sign in to comment.