This repository was archived by the owner on Oct 7, 2024. It is now read-only.
generated from MetaMask/metamask-module-template
-
-
Notifications
You must be signed in to change notification settings - Fork 6
feat: add getAccountBalances method to Keyring
#320
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b6882da
refactor: split `api.ts`
danroc c2c2ad8
chore: add missing return type
danroc b5c66bd
chore: add import to use `CaipAssetTypeStruct`
danroc a0390c6
chore: update asset type
danroc 71ecd19
chore: update assets array type
danroc 7d5adc0
chore: update error message in unit test
danroc 605a461
chore: fix Sonar warning
danroc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,19 @@ | ||
| import { expectAssignable, expectNotAssignable } from 'tsd'; | ||
|
|
||
| import type { Balance } from './balance'; | ||
|
|
||
| expectAssignable<Balance>({ amount: '1.0', unit: 'ETH' }); | ||
| expectAssignable<Balance>({ amount: '0.1', unit: 'BTC' }); | ||
| expectAssignable<Balance>({ amount: '.1', unit: 'gwei' }); | ||
| expectAssignable<Balance>({ amount: '.1', unit: 'wei' }); | ||
| expectAssignable<Balance>({ amount: '1.', unit: 'sat' }); | ||
|
|
||
| expectNotAssignable<Balance>({ amount: 1, unit: 'ETH' }); | ||
| expectNotAssignable<Balance>({ amount: true, unit: 'ETH' }); | ||
| expectNotAssignable<Balance>({ amount: undefined, unit: 'ETH' }); | ||
| expectNotAssignable<Balance>({ amount: null, unit: 'ETH' }); | ||
|
|
||
| expectNotAssignable<Balance>({ amount: '1.0', unit: 1 }); | ||
| expectNotAssignable<Balance>({ amount: '1.0', unit: true }); | ||
| expectNotAssignable<Balance>({ amount: '1.0', unit: undefined }); | ||
| expectNotAssignable<Balance>({ amount: '1.0', unit: null }); |
This file contains hidden or 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,12 @@ | ||
| import type { Infer } from 'superstruct'; | ||
| import { string } from 'superstruct'; | ||
|
|
||
| import { object } from '../superstruct'; | ||
| import { StringNumberStruct } from '../utils'; | ||
|
|
||
| export const BalanceStruct = object({ | ||
| amount: StringNumberStruct, | ||
| unit: string(), | ||
| }); | ||
|
|
||
| export type Balance = Infer<typeof BalanceStruct>; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,4 +1,3 @@ | ||
| export * from './caip'; | ||
| export * from './types'; | ||
| export * from './typing'; | ||
| export * from './url'; | ||
| export * from './uuid'; |
This file contains hidden or 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,19 @@ | ||
| import { is } from 'superstruct'; | ||
|
|
||
| import { StringNumberStruct } from './types'; | ||
|
|
||
| describe('StringNumber', () => { | ||
| it.each(['0', '0.0', '0.1', '0.19', '00.19', '0.000000000000000000000'])( | ||
| 'validates basic number: %s', | ||
| (input: string) => { | ||
| expect(is(input, StringNumberStruct)).toBe(true); | ||
| }, | ||
| ); | ||
|
|
||
| it.each(['foobar', 'NaN', '0.123.4', '1e3', undefined, null, 1, true])( | ||
| 'fails to validate wrong number: %s', | ||
| (input: any) => { | ||
| expect(is(input, StringNumberStruct)).toBe(false); | ||
| }, | ||
| ); | ||
| }); |
This file contains hidden or 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,35 @@ | ||
| import { define, type Infer } from 'superstruct'; | ||
|
|
||
| import { definePattern } from '../superstruct'; | ||
|
|
||
| /** | ||
| * UUIDv4 struct. | ||
| */ | ||
| export const UuidStruct = definePattern( | ||
| 'UuidV4', | ||
| /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu, | ||
| ); | ||
|
|
||
| /** | ||
| * Validates if a given value is a valid URL. | ||
| * | ||
| * @param value - The value to be validated. | ||
| * @returns A boolean indicating if the value is a valid URL. | ||
| */ | ||
| export const UrlStruct = define<string>('Url', (value: unknown) => { | ||
| try { | ||
| const url = new URL(value as string); | ||
| return url.protocol === 'http:' || url.protocol === 'https:'; | ||
| } catch (_) { | ||
| return false; | ||
| } | ||
| }); | ||
|
|
||
| /** | ||
| * A string which contains a positive float number. | ||
| */ | ||
| export const StringNumberStruct = definePattern( | ||
| 'StringNumber', | ||
| /^\d+(\.\d+)?$/u, | ||
| ); | ||
| export type StringNumber = Infer<typeof StringNumberStruct>; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.