Skip to content

Commit

Permalink
support update currency rate manually (#390)
Browse files Browse the repository at this point in the history
* support update currency rate manually

* support update currency rate manually
  • Loading branch information
domechn authored May 5, 2024
1 parent 267a63f commit 2addd29
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/components/configuration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
saveConfiguration,
savePreferCurrency,
saveQuerySize,
updateAllCurrencyRates,
} from "@/middlelayers/configuration";
import { useToast } from "@/components/ui/use-toast";
import DeleteIcon from "@/assets/icons/delete-icon.png";
Expand Down Expand Up @@ -42,7 +43,7 @@ import {
import { Input } from "@/components/ui/input";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { CexAnalyzer } from "@/middlelayers/datafetch/coins/cex/cex";
import { ReloadIcon } from "@radix-ui/react-icons";
import { ReloadIcon, UpdateIcon } from "@radix-ui/react-icons";
import { BTCAnalyzer } from "@/middlelayers/datafetch/coins/btc";
import { DOGEAnalyzer } from "@/middlelayers/datafetch/coins/doge";
import { SOLAnalyzer } from "@/middlelayers/datafetch/coins/sol";
Expand All @@ -51,6 +52,12 @@ import { TRC20ProUserAnalyzer } from "@/middlelayers/datafetch/coins/trc20";
import { getWalletLogo } from "@/lib/utils";
import { prettyPriceNumberToLocaleString } from "@/utils/currency";
import { TonAnalyzer } from "@/middlelayers/datafetch/coins/ton";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "./ui/tooltip";

const initialConfiguration: GlobalConfig = {
configs: {
Expand Down Expand Up @@ -168,6 +175,8 @@ const App = ({ onConfigurationSave }: { onConfigurationSave?: () => void }) => {
const [saveCexConfigLoading, setSaveCexConfigLoading] = useState(false);
const [saveWalletConfigLoading, setSaveWalletConfigLoading] = useState(false);

const [refreshCurrencyLoading, setRefreshCurrencyLoading] = useState(false);

const [addExchangeConfig, setAddExchangeConfig] = useState<
| {
type: string;
Expand Down Expand Up @@ -727,6 +736,16 @@ const App = ({ onConfigurationSave }: { onConfigurationSave?: () => void }) => {
return ana.verifyConfigs();
}

async function updateCurrencyRates() {
setRefreshCurrencyLoading(true);
try {
await updateAllCurrencyRates();
await loadSupportedCurrencies()
} finally {
setRefreshCurrencyLoading(false);
}
}

function renderAddExchangeForm() {
return (
<Dialog
Expand Down Expand Up @@ -1133,6 +1152,22 @@ const App = ({ onConfigurationSave }: { onConfigurationSave?: () => void }) => {
</SelectGroup>
</SelectContent>
</Select>
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<UpdateIcon
className={`mr-2 h-4 w-4 cursor-pointer ${
refreshCurrencyLoading && "animate-spin"
}`}
onClick={updateCurrencyRates}
/>
</TooltipTrigger>
<TooltipContent>
<p>Refresh Currency Rates</p>
</TooltipContent>
</Tooltip>
</TooltipProvider>

{preferredCurrencyDetail &&
preferCurrency !== defaultBaseCurrency && (
<div className="text-muted-foreground text-sm">
Expand Down

0 comments on commit 2addd29

Please sign in to comment.