forked from flexpool/frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
259 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { getPropsFromLocateAddress } from './utils'; | ||
const mockGetLocateAddress = jest.fn(); | ||
|
||
jest.mock('@/api', () => { | ||
return { | ||
getLocateAddress: () => mockGetLocateAddress(), | ||
}; | ||
}); | ||
|
||
describe('getPropsFromLocateAddress', () => { | ||
it('handles correctly for incorrect address format', async () => { | ||
mockGetLocateAddress.mockResolvedValue({ | ||
pendingStats: false, | ||
result: null, | ||
all: [], | ||
}); | ||
|
||
const { dashboards, addressStatus, isAddressValid } = | ||
await getPropsFromLocateAddress('0x0'); | ||
|
||
expect(dashboards).toEqual([]); | ||
expect(addressStatus).toEqual('not-found'); | ||
expect(isAddressValid).toEqual(false); | ||
}); | ||
|
||
it('handles correctly for wallet mining only ethereum', async () => { | ||
mockGetLocateAddress.mockResolvedValue({ | ||
pendingStats: false, | ||
result: 'eth', | ||
all: ['eth'], | ||
}); | ||
|
||
const { dashboards, addressStatus, isAddressValid } = | ||
await getPropsFromLocateAddress( | ||
'0xb794f5ea0ba39494ce839613fffba74279579268' | ||
); | ||
|
||
expect(dashboards).toEqual(['eth']); | ||
expect(addressStatus).toEqual('mining'); | ||
expect(isAddressValid).toEqual(true); | ||
}); | ||
|
||
it('handles correctly for wallet mining only chia', async () => { | ||
mockGetLocateAddress.mockResolvedValue({ | ||
pendingStats: false, | ||
result: 'xch', | ||
all: ['xch'], | ||
}); | ||
|
||
const { dashboards, addressStatus, isAddressValid } = | ||
await getPropsFromLocateAddress( | ||
'xch1ch36xj8vtc2yr72f95u7nr36ykdtfsz0l2cannpskr6n46m6m2zsh8husq' | ||
); | ||
|
||
expect(dashboards).toEqual(['xch']); | ||
expect(addressStatus).toEqual('mining'); | ||
expect(isAddressValid).toEqual(true); | ||
}); | ||
|
||
it('handles correctly for wallet mining only etc', async () => { | ||
mockGetLocateAddress.mockResolvedValue({ | ||
pendingStats: false, | ||
result: 'etc', | ||
all: ['etc'], | ||
}); | ||
|
||
const { dashboards, addressStatus, isAddressValid } = | ||
await getPropsFromLocateAddress( | ||
'xch1ch36xj8vtc2yr72f95u7nr36ykdtfsz0l2cannpskr6n46m6m2zsh8husq' | ||
); | ||
|
||
expect(dashboards).toEqual(['etc']); | ||
expect(addressStatus).toEqual('mining'); | ||
expect(isAddressValid).toEqual(true); | ||
}); | ||
|
||
it('handles correctly for wallet mining both eth and etc', async () => { | ||
mockGetLocateAddress.mockResolvedValue({ | ||
pendingStats: false, | ||
result: 'eth', | ||
all: ['eth', 'etc'], | ||
}); | ||
|
||
const { dashboards, addressStatus, isAddressValid } = | ||
await getPropsFromLocateAddress( | ||
'0xb794f5ea0ba39494ce839613fffba74279579268' | ||
); | ||
|
||
expect(dashboards).toEqual(['eth', 'etc']); | ||
expect(addressStatus).toEqual('mining'); | ||
expect(isAddressValid).toEqual(true); | ||
}); | ||
|
||
it('handles correctly for pending eth wallet ', async () => { | ||
mockGetLocateAddress.mockResolvedValue({ | ||
pendingStats: true, | ||
result: null, | ||
all: [], | ||
}); | ||
|
||
const { dashboards, addressStatus, isAddressValid } = | ||
await getPropsFromLocateAddress( | ||
'0xb794f5ea0ba39494ce839613fffba74279579268' | ||
); | ||
|
||
expect(dashboards).toEqual(['eth', 'etc']); | ||
expect(addressStatus).toEqual('pending'); | ||
expect(isAddressValid).toEqual(true); | ||
}); | ||
|
||
it('handles correctly for pending xch wallet ', async () => { | ||
mockGetLocateAddress.mockResolvedValue({ | ||
pendingStats: true, | ||
result: null, | ||
all: [], | ||
}); | ||
|
||
const { dashboards, addressStatus, isAddressValid } = | ||
await getPropsFromLocateAddress( | ||
'xch1ch36xj8vtc2yr72f95u7nr36ykdtfsz0l2cannpskr6n46m6m2zsh8husq' | ||
); | ||
|
||
expect(dashboards).toEqual(['xch']); | ||
expect(addressStatus).toEqual('pending'); | ||
expect(isAddressValid).toEqual(true); | ||
}); | ||
}); |
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,36 @@ | ||
import { getLocateAddress } from '@/api'; | ||
import { getChecksumByTicker } from '@/utils/validators/checksum'; | ||
import { AddressStatus } from '@/pages/Search/AddressCard'; | ||
|
||
export const getPropsFromLocateAddress = async ( | ||
address: string | undefined | ||
) => { | ||
let addressStatus: AddressStatus = 'not-found'; | ||
let dashboards: string[] = []; | ||
let addressType: string | undefined = undefined; | ||
|
||
if (address) { | ||
const result = await getLocateAddress(address); | ||
|
||
if (getChecksumByTicker('eth')(address)) addressType = 'eth'; | ||
if (getChecksumByTicker('xch')(address)) addressType = 'xch'; | ||
|
||
const isPending = result.pendingStats === true; | ||
const isMining = !isPending && result.result !== null; | ||
|
||
if (isPending) { | ||
if (addressType === 'eth') dashboards = ['eth', 'etc']; | ||
if (addressType === 'xch') dashboards = ['xch']; | ||
addressStatus = 'pending'; | ||
} else if (isMining) { | ||
dashboards = result.all; | ||
addressStatus = 'mining'; | ||
} | ||
} | ||
|
||
return { | ||
dashboards, | ||
addressStatus, | ||
isAddressValid: addressType !== undefined, | ||
}; | ||
}; |
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,81 @@ | ||
import { reducer } from './addressSearch.reducer'; | ||
import { addressSearchSet } from './addressSearch.actions'; | ||
|
||
describe('addressSearch reducer should handle items being added to the list', () => { | ||
it('should handle single item', () => { | ||
expect( | ||
reducer( | ||
undefined, | ||
addressSearchSet({ | ||
address: 'address_0', | ||
coin: 'eth', | ||
}) | ||
) | ||
).toEqual([ | ||
{ | ||
address: 'address_0', | ||
coin: 'eth', | ||
}, | ||
]); | ||
}); | ||
|
||
it('should handle multiple items', () => { | ||
expect( | ||
reducer( | ||
[ | ||
{ | ||
address: 'address_0', | ||
coin: 'eth', | ||
}, | ||
{ | ||
address: 'address_1', | ||
coin: 'eth', | ||
}, | ||
], | ||
addressSearchSet({ | ||
address: 'address_1', | ||
coin: 'eth', | ||
}) | ||
) | ||
).toEqual([ | ||
{ | ||
address: 'address_1', | ||
coin: 'eth', | ||
}, | ||
{ | ||
address: 'address_0', | ||
coin: 'eth', | ||
}, | ||
]); | ||
}); | ||
|
||
it('should handle complex item', () => { | ||
expect( | ||
reducer( | ||
[ | ||
{ | ||
address: 'address_0', | ||
coin: 'eth', | ||
}, | ||
{ | ||
address: 'address_1', | ||
coin: null, | ||
}, | ||
], | ||
addressSearchSet({ | ||
address: 'address_1', | ||
coin: ['eth', 'etc'], | ||
}) | ||
) | ||
).toEqual([ | ||
{ | ||
address: 'address_1', | ||
coin: ['eth', 'etc'], | ||
}, | ||
{ | ||
address: 'address_0', | ||
coin: 'eth', | ||
}, | ||
]); | ||
}); | ||
}); |