-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* init remove column, #5125 * add remove proxy tx func, #5125 * add myProxies redux, #5125 * Refactor: replace provider with myProxies redux, #5125 * remove useless loading const, #5125 * updateMyproxies, #5125 * add subscribe MyProxies context, #5125 * remove myproxiesSlice, #5125 * modify toast, #5125 * format code, #5125 * remove paginations from myProxies, #5125
- Loading branch information
Showing
13 changed files
with
113 additions
and
72 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import RemoveProxy from "./operations/removeProxy"; | ||
|
||
export * from "next-common/components/profile/proxy/common/columns"; | ||
|
||
export const removeColumn = { | ||
name: "", | ||
className: "text-right w-20", | ||
render: (data) => <RemoveProxy data={data} />, | ||
}; |
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
47 changes: 47 additions & 0 deletions
47
packages/next-common/components/myProxies/common/operations/removeProxy.jsx
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,47 @@ | ||
import { useCallback, useState, useEffect } from "react"; | ||
import { useContextApi } from "next-common/context/api"; | ||
import useRealAddress from "next-common/utils/hooks/useRealAddress"; | ||
import useTxSubmission from "next-common/components/common/tx/useTxSubmission"; | ||
import RemoveButton from "next-common/components/removeButton"; | ||
import Tooltip from "next-common/components/tooltip"; | ||
import { useDispatch } from "react-redux"; | ||
import { newSuccessToast } from "next-common/store/reducers/toastSlice"; | ||
|
||
export default function RemoveProxy({ data }) { | ||
const api = useContextApi(); | ||
const address = useRealAddress(); | ||
const dispatch = useDispatch(); | ||
const [isDisabled, setIsDisabled] = useState(false); | ||
|
||
const getTxFunc = useCallback(() => { | ||
if (!api || !address) { | ||
return; | ||
} | ||
|
||
const { delegate, proxyType, delay } = data; | ||
return api.tx.proxy.removeProxy(delegate, proxyType, delay); | ||
}, [api, address, data]); | ||
|
||
const onFinalized = () => { | ||
setIsDisabled(false); | ||
dispatch(newSuccessToast("Removed successfully")); | ||
}; | ||
|
||
const { doSubmit, isSubmitting } = useTxSubmission({ | ||
getTxFunc, | ||
onFinalized, | ||
onCancelled: () => setIsDisabled(false), | ||
}); | ||
|
||
useEffect(() => { | ||
if (isSubmitting) { | ||
setIsDisabled(true); | ||
} | ||
}, [isSubmitting]); | ||
|
||
return ( | ||
<Tooltip content="Remove"> | ||
<RemoveButton disabled={isDisabled} onClick={doSubmit} /> | ||
</Tooltip> | ||
); | ||
} |
6 changes: 3 additions & 3 deletions
6
packages/next-common/components/myProxies/context/myProxies.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
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
22 changes: 15 additions & 7 deletions
22
packages/next-common/components/overview/account/proxiesTitle.jsx
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 |
---|---|---|
@@ -1,18 +1,26 @@ | ||
import { Title } from "./styled"; | ||
import useMyOnChainProxies from "next-common/hooks/account/useMyOnChainProxies"; | ||
import { | ||
useMyProxiesContext, | ||
MyProxiesProvider, | ||
} from "next-common/components/myProxies/context/myProxies"; | ||
|
||
function ProxiesCount() { | ||
const { proxies = [] } = useMyOnChainProxies(); | ||
const total = proxies[0]?.length || 0; | ||
const { total = 0, loading } = useMyProxiesContext(); | ||
|
||
if (loading) { | ||
return null; | ||
} | ||
|
||
return <span className="text-textTertiary mx-1 text16Medium">{total}</span>; | ||
} | ||
|
||
export default function ProxiesTitle({ active }) { | ||
return ( | ||
<Title className={active ? "text-textPrimary" : "text-textTertiary"}> | ||
Proxies | ||
<ProxiesCount /> | ||
</Title> | ||
<MyProxiesProvider> | ||
<Title className={active ? "text-textPrimary" : "text-textTertiary"}> | ||
Proxies | ||
<ProxiesCount /> | ||
</Title> | ||
</MyProxiesProvider> | ||
); | ||
} |
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 was deleted.
Oops, something went wrong.
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,9 @@ | ||
import useRealAddress from "next-common/utils/hooks/useRealAddress"; | ||
import useSubStorage from "next-common/hooks/common/useSubStorage"; | ||
|
||
export default function useSubMyProxies() { | ||
const address = useRealAddress(); | ||
const { result, loading } = useSubStorage("proxy", "proxies", [address]); | ||
|
||
return { proxies: result?.toJSON(), loading }; | ||
} |