This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add function to get token balance from metamask
- Loading branch information
1 parent
6e8f5d2
commit 9a157a9
Showing
4 changed files
with
25 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ test/server/data.js | |
build | ||
dist | ||
.vscode/ | ||
metamask | ||
/metamask | ||
.idea | ||
*.log | ||
test/dapp/data.js |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Page } from 'puppeteer'; | ||
|
||
export const getTokenBalance = (page: Page) => async (tokenSymbol: string): Promise<number> => { | ||
await page.bringToFront(); | ||
await page.waitForTimeout(1000); | ||
|
||
const assetListItems = await page.$$('.asset-list-item__token-button'); | ||
|
||
for (let index = 0; index < assetListItems.length; index++) { | ||
const assetListItem = assetListItems[index]; | ||
|
||
const titleAttributeValue: string = await page.evaluate((item) => item.getAttribute('title'), assetListItem); | ||
|
||
if (titleAttributeValue.split(' ')[1].toUpperCase() === tokenSymbol.toUpperCase()) { | ||
const balance = titleAttributeValue.split(' ')[0]; | ||
return parseFloat(balance); | ||
} | ||
} | ||
|
||
return 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