This repository has been archived by the owner on Dec 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now handling parameters for the snap RPC APIs
- Loading branch information
Showing
16 changed files
with
219 additions
and
72 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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,54 @@ | ||
import _ from 'lodash'; | ||
import { HederaAccountInfo } from 'src/services/hedera'; | ||
import { createHederaClient } from '../../snap/account'; | ||
import { updateSnapState } from '../../snap/state'; | ||
import { AccountInfo } from '../../types/account'; | ||
import { PulseSnapParams } from '../../types/state'; | ||
|
||
/** | ||
* Get account info such as address, did, public key, etc. | ||
* | ||
* @param pulseSnapParams - Pulse snap params. | ||
* @param accountId - Hedera Account Id. | ||
* @returns Account Info. | ||
*/ | ||
export async function getAccountInfo( | ||
pulseSnapParams: PulseSnapParams, | ||
): Promise<AccountInfo> { | ||
accountId?: string, | ||
): Promise<any> { | ||
const { state } = pulseSnapParams; | ||
|
||
const { metamaskAddress, hederaAccountId, network } = state.currentAccount; | ||
|
||
let accountInfo = {}; | ||
|
||
try { | ||
const hederaClient = await createHederaClient( | ||
state.accountState[metamaskAddress].keyStore.privateKey, | ||
hederaAccountId, | ||
network, | ||
); | ||
|
||
const response = await hederaClient.getAccountInfo(hederaAccountId); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
state.accountState[metamaskAddress].accountInfo.balance!.hbars = Number( | ||
response.balance.toString().replace(' ℏ', ''), | ||
); | ||
let response: HederaAccountInfo; | ||
if (accountId && !_.isEmpty(accountId)) { | ||
response = await hederaClient.getAccountInfo(accountId); | ||
} else { | ||
response = await hederaClient.getAccountInfo(hederaAccountId); | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
state.accountState[metamaskAddress].accountInfo.balance!.hbars = Number( | ||
response.balance.toString().replace(' ℏ', ''), | ||
); | ||
|
||
// Let's massage the info we want rather than spitting out everything | ||
state.accountState[metamaskAddress].accountInfo.extraData = JSON.parse( | ||
JSON.stringify(response), | ||
); | ||
await updateSnapState(snap, state); | ||
// TODO: still need to update state.accountState[metamaskAddress].accountInfo.balance | ||
// Let's massage the info we want rather than spitting out everything | ||
state.accountState[metamaskAddress].accountInfo.extraData = JSON.parse( | ||
JSON.stringify(response), | ||
); | ||
await updateSnapState(snap, state); | ||
} | ||
accountInfo = JSON.parse(JSON.stringify(response)); | ||
} catch (error: any) { | ||
console.error(`Error while trying to get account info: ${String(error)}`); | ||
throw new Error(`Error while trying to get account info: ${String(error)}`); | ||
} | ||
|
||
return state.accountState[metamaskAddress].accountInfo; | ||
return accountInfo; | ||
} |
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
Oops, something went wrong.