-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: integrate multichain assets rates controller to extension UI
- Loading branch information
Showing
6 changed files
with
91 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { getAssetsRates, AssetsState } from './multichain-assets-rates'; | ||
|
||
// Mock state for testing | ||
const mockState = { | ||
metamask: { | ||
assetsRates: { | ||
'token-1': { rate: 1.5, currency: 'USD' }, | ||
'token-2': { rate: 0.8, currency: 'EUR' }, | ||
}, | ||
}, | ||
}; | ||
describe('getAssetsRates', () => { | ||
it('should return the assetsRates from the state', () => { | ||
const result = getAssetsRates(mockState); | ||
expect(result).toEqual(mockState.metamask.assetsRates); | ||
}); | ||
|
||
it('should return an empty object if assetsRates is empty', () => { | ||
const emptyState: AssetsState = { | ||
metamask: { | ||
assetsRates: {}, | ||
}, | ||
}; | ||
const result = getAssetsRates(emptyState); | ||
expect(result).toEqual({}); | ||
}); | ||
|
||
it('should return undefined if state does not have metamask property', () => { | ||
const invalidState = {} as AssetsState; | ||
expect(() => getAssetsRates(invalidState)).toThrow(); | ||
}); | ||
}); |
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,15 @@ | ||
import { MultichainAssetsRatesControllerState } from '@metamask/assets-controllers'; | ||
|
||
export type AssetsState = { | ||
metamask: MultichainAssetsRatesControllerState; | ||
}; | ||
|
||
/** | ||
* Gets non-EVM accounts assets. | ||
* | ||
* @param state - Redux state object. | ||
* @returns An object containing non-EVM assets per accounts. | ||
*/ | ||
export function getAssetsRates(state: AssetsState) { | ||
return state.metamask.assetsRates; | ||
} |