{"id":20046356,"url":"https://github.com/aneldev/dynadux-currencies-section","last_synced_at":"2025-06-27T11:32:11.956Z","repository":{"id":40787687,"uuid":"253556267","full_name":"aneldev/dynadux-currencies-section","owner":"aneldev","description":"Currencies section for Dynadux stores","archived":false,"fork":false,"pushed_at":"2022-12-12T09:57:23.000Z","size":4122,"stargazers_count":0,"open_issues_count":20,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-13T13:43:36.396Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aneldev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-06T16:34:38.000Z","updated_at":"2020-06-19T12:58:47.000Z","dependencies_parsed_at":"2023-01-27T17:25:15.881Z","dependency_job_id":null,"html_url":"https://github.com/aneldev/dynadux-currencies-section","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aneldev%2Fdynadux-currencies-section","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aneldev%2Fdynadux-currencies-section/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aneldev%2Fdynadux-currencies-section/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aneldev%2Fdynadux-currencies-section/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aneldev","download_url":"https://codeload.github.com/aneldev/dynadux-currencies-section/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241476435,"owners_count":19968916,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T11:23:16.918Z","updated_at":"2025-03-02T07:48:39.012Z","avatar_url":"https://github.com/aneldev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# About\n\n[Dynadux](https://github.com/aneldev/dynadux) Section for Currencies.\n\n# Usage\n\n_In Typescript_\n\nLet's create a function that creates the app store and uses this package.\n\n```\nimport {createCurrenciesSection} from \"dynadux-currencies-section\";\n\ninterface IState {\n  // ... other sections or state props\n  currenciesSection: ICreateCurrenciesSectionState;\n}\n\nconst createAppStore = (onChange: (state: IState) =\u003e void) =\u003e {\n  const store = createStore\u003cIState\u003e({onChange});\n\n  return {\n   // ... other parts of the store\n   currencies: createCurrenciesSection({\n      sectionName: 'currenciesSection',\n      store,\n      defaultCurrency: 'eur',\n      updateIfOldenThanMinutes: 30,\n      getCurrencies, // A currencies rates getter\n    })\n  };\n};\n\n```\nLets use the store.\n```\nconst appStore = createAppStore({onChange: ()=\u003e ... });\n\n// Wait to load the rates\nawait appStore.currencies.loadRates();\n\n// Switch currency\nappStore.currencies.currency = 'usd';\n\n// Convert eur (to current currency usd)\nconst usdValue = appStore.currencies.convert(12.20, 'eur'); // 11.09\n\n```\n\n# createCurrenciesSection config\n\n```\ninterface ICreateCurrenciesSectionConfig {\n  store: ICreateStoreAPI;   // Dynadux store\n  sectionName: string;\n  defaultCurrency: string;\n  getCurrencies: () =\u003e Promise\u003cICurrencyRates\u003e;\n  updateIfOldenThanMinutes?: number;\n}\n\ninterface ICurrencyRates {\n  [currencyName: string]: number | undefined;\n}\n```\n# createCurrenciesSection State\n\nThe State is at the `sectionName` of the config. But in practice, you don't have to access the State since the API has everything that you want.\n\nMaybe, the most notable is the `currency` prop.\n\n```\nICreateCurrenciesSectionState {\n  loadState: 'empty' | 'loading' | 'loaded';\n  currency: string;\n  currencies: DynaCurrencies;\n  error: string;\n  lastUpdate: Date | null;\n}\n```\n\nAlso, the `currencies: DynaCurrencies` is the instance of the [DynaCurrencies](https://github.com/aneldev/dyna-currencies) converter, that offers a list of currencies, etc.. Checkout it's repo to see what it offers.\n\n# createCurrenciesSection API\n\n#### currency: string\n\nGet and set the current currency.\n\n#### hasLoadedRates: boolean\n\nBoolean to know if the rates are loaded\n\n#### loadRates: (): Promise\u003cvoid\u003e\n\nUses the `getCurrencies` of the config to get the rates.\n\n#### convert: (value: number, sourceCurrency: string, round = false): number | null\n\nRate converter to current currency. \n\nReturns null if the rates are not loaded, or when the currency is wrong.\n\n#### convertDynaPrice: (price: IDynaPrice): IDynaPrice | null\n\nConvert an IDynaPrice to the current currency.\n\n#### convertToLabel: (value: number, sourceCurrency: string): IDynaLabelCurrency | null\n\nConvert and create an IDynaLabelCurrency\n\n#### getCurrencyRates: async (): Promise\u003cICurrencyRates\u003e\n\nIt loads or returns the already loaded currencies.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faneldev%2Fdynadux-currencies-section","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faneldev%2Fdynadux-currencies-section","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faneldev%2Fdynadux-currencies-section/lists"}