Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dmy147 committed Sep 13, 2023
1 parent 1a14dfc commit 0028b5e
Show file tree
Hide file tree
Showing 13 changed files with 506 additions and 86 deletions.
12 changes: 12 additions & 0 deletions __tests__/migration/contactMigration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ const data: { preference: PreferenceStore; contactBook } = {
walletSavedList: [],
watchAddressPreference: {},
testnetBalanceMap: {},
addressSortStore: {
search: '',
sortType: 'usd',
},
},
contactBook: {
'0x10b26700b0a2d3f5ef12fa250aba818ee3b43bf4': {
Expand Down Expand Up @@ -188,6 +192,10 @@ test('should migrate when no alians', () => {
walletSavedList: [],
watchAddressPreference: {},
testnetBalanceMap: {},
addressSortStore: {
search: '',
sortType: 'usd',
},
},
contactBook: {
'0x10b26700b0a2d3f5ef12fa250aba818ee3b43bf4': {
Expand Down Expand Up @@ -316,6 +324,10 @@ test('should migrate when no contacts', () => {
walletSavedList: [],
watchAddressPreference: {},
testnetBalanceMap: {},
addressSortStore: {
search: '',
sortType: 'usd',
},
},
contactBook: {},
};
Expand Down
3 changes: 3 additions & 0 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,9 @@ export class WalletController extends BaseController {
getLastSelectedGasTopUpChain = preferenceService.getLastSelectedGasTopUpChain;
setLastSelectedGasTopUpChain = preferenceService.setLastSelectedGasTopUpChain;

getAddressSortStoreValue = preferenceService.getAddressSortStoreValue;
setAddressSortStoreValue = preferenceService.setAddressSortStoreValue;

getLastSelectedSwapChain = swapService.getSelectedChain;
setLastSelectedSwapChain = swapService.setSelectedChain;
getSwap = swapService.getSwap;
Expand Down
31 changes: 31 additions & 0 deletions src/background/service/preference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,20 @@ export interface PreferenceStore {
autoLockTime?: number;
hiddenBalance?: boolean;
isShowTestnet?: boolean;
addressSortStore: AddressSortStore;
}

export interface AddressSortStore {
search: string;
sortType: 'usd' | 'addressType' | 'alphabet';
lastCurrent?: string;
}

const defaultAddressSortStore: AddressSortStore = {
search: '',
sortType: 'usd',
};

class PreferenceService {
store!: PreferenceStore;
popupOpen = false;
Expand Down Expand Up @@ -133,8 +145,14 @@ class PreferenceService {
collectionStarred: [],
hiddenBalance: false,
isShowTestnet: false,
addressSortStore: {
...defaultAddressSortStore,
},
},
});
//lifetime in background
this.store.addressSortStore = { ...defaultAddressSortStore };

if (
!this.store.locale ||
!LANGS.find((item) => item.code === this.store.locale)
Expand Down Expand Up @@ -691,6 +709,19 @@ class PreferenceService {
resetCurrentCoboSafeAddress = async () => {
this.setCurrentAccount(this.currentCoboSafeAddress ?? null);
};

getAddressSortStoreValue = (key: keyof AddressSortStore) =>
this.store.addressSortStore[key];

setAddressSortStoreValue = <K extends keyof AddressSortStore>(
key: K,
value: AddressSortStore[K]
) => {
this.store.addressSortStore = {
...this.store.addressSortStore,
[key]: value,
};
};
}

export default new PreferenceService();
5 changes: 5 additions & 0 deletions src/ui/assets/address/checked.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions src/ui/assets/address/sort-by-alphabet.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions src/ui/assets/address/sort-by-type.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions src/ui/assets/address/sort-by-usd.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions src/ui/component/AddressList/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,40 @@
}
.address-wrap-with-padding {
.address-wrap;
margin-bottom: 0;

&.group:nth-child(n + 2) {
.rabby-address-item-container .rabby-address-item {
position: relative;
&::after {
position: absolute;
top: 0;
left: 0;
content: '';
width: 100%;
height: 0;
border-top: 0.5px solid var(--r-neutral-line, #d3d8e0);
}
}
}

&.group:nth-child(1) {
.rabby-address-item-container .rabby-address-item {
border-top-left-radius: 6px;
border-top-right-radius: 6px;
}
}
&.group:nth-last-child(1) {
.rabby-address-item-container .rabby-address-item {
border-bottom-left-radius: 6px;
border-bottom-right-radius: 6px;
}
}

&.group .rabby-address-item-container .rabby-address-item {
border-radius: 0;
}

&:nth-last-child(1) {
padding-bottom: 200px;
}
Expand Down
21 changes: 20 additions & 1 deletion src/ui/models/preference.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { createModel } from '@rematch/core';
import { RootModel } from '.';
import { TokenItem } from 'background/service/openapi';
import { GasCache, addedToken } from 'background/service/preference';
import {
AddressSortStore,
GasCache,
addedToken,
} from 'background/service/preference';
import { CHAINS_ENUM } from 'consts';
import i18n from '@/i18n';

Expand All @@ -22,6 +26,7 @@ interface PreferenceState {
autoLockTime: number;
hiddenBalance: boolean;
isShowTestnet: boolean;
addressSortStore: AddressSortStore;
}

export const preference = createModel<RootModel>()({
Expand All @@ -44,6 +49,7 @@ export const preference = createModel<RootModel>()({
autoLockTime: 0,
hiddenBalance: false,
isShowTestnet: false,
addressSortStore: {} as AddressSortStore,
} as PreferenceState,

reducers: {
Expand Down Expand Up @@ -179,6 +185,19 @@ export const preference = createModel<RootModel>()({
dispatch.preference.getPreference('locale');
},

async getAddressSortStoreValue(key: keyof AddressSortStore, store?) {
const value = await store.app.wallet.getAddressSortStoreValue(key);
return value;
},

async setAddressSortStoreValue<K extends keyof AddressSortStore>(
{ key, value }: { key: K; value: AddressSortStore[K] },
store?
) {
await store.app.wallet.setAddressSortStoreValue(key, value);
dispatch.preference.getPreference('addressSortStore');
},

// async setOpenapiHost(value: string, store?) {
// dispatch.preference.setField({
// isShowTestnet: value,
Expand Down
81 changes: 81 additions & 0 deletions src/ui/views/AddressManagement/SortPopup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Item, Popup } from '@/ui/component';
import React, { useMemo } from 'react';
import ImgSortByUsd from '@/ui/assets/address/sort-by-usd.svg';
import ImgSortByType from '@/ui/assets/address/sort-by-type.svg';
import ImgSortByAlphabet from '@/ui/assets/address/sort-by-alphabet.svg';
import ImgChecked from '@/ui/assets/address/checked.svg';

import { useRabbyDispatch, useRabbySelector } from '@/ui/store';
import { AddressSortStore } from '@/background/service/preference';

export const AddressSortIconMapping: Record<
AddressSortStore['sortType'],
string
> = {
usd: ImgSortByUsd,
addressType: ImgSortByType,
alphabet: ImgSortByAlphabet,
};

export const AddressSortPopup = ({
open,
onCancel,
}: {
open: boolean;
onCancel: () => void;
}) => {
const sortType = useRabbySelector(
(s) => s.preference.addressSortStore.sortType
);
const dispath = useRabbyDispatch();
const handleChange = (value: AddressSortStore['sortType']) => () => {
dispath.preference.setAddressSortStoreValue({ key: 'sortType', value });
onCancel?.();
};

const arr = useMemo(
() =>
[
{
key: 'usd',
label: '按地址金额排序',
},
{
key: 'addressType',
label: '按地址类型排序',
},
{
key: 'alphabet',
label: '按地址备注首字母排序',
},
] as const,
[]
);
return (
<Popup
title={'地址排序'}
closable
visible={open}
height={258}
onCancel={onCancel}
>
<div className="flex flex-col gap-8">
{arr.map((e) => (
<Item
key={e.key}
py={13}
bgColor="var(--r-neutral-card-2, #F2F4F7)"
leftIcon={AddressSortIconMapping[e.key]}
onClick={handleChange(e.key)}
className="text-14 text-r-neutral-title-1 font-normal"
leftIconClassName="mr-12 w-20"
rightIcon={sortType === e.key ? ImgChecked : null}
rightIconClassName="w-20"
>
{e.label}
</Item>
))}
</div>
</Popup>
);
};
Loading

0 comments on commit 0028b5e

Please sign in to comment.