forked from deriv-com/deriv-app
-
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.
Vinu/Wallet names from be (deriv-com#5302)
* made wallet names to be dynamic from backend * resolved linting issue * implemented review comments and also added wrapper component for create-wallet for storybook to work * fixed linting issue * minor fix in wallet-store onUnmount function * implemented the review comments in create-wallet * resolved linting issue * added all account types in wallet store * changed function name in wallet store
- Loading branch information
1 parent
c470bd3
commit 0251f43
Showing
9 changed files
with
237 additions
and
67 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
56 changes: 0 additions & 56 deletions
56
packages/appstore/src/components/create-wallet/create-wallet-provider.ts
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
packages/appstore/src/components/create-wallet/create-wallet-wrapper.tsx
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,24 @@ | ||
import { observer } from 'mobx-react-lite'; | ||
import React from 'react'; | ||
import { useStores } from 'Stores'; | ||
import CreateWallet from './create-wallet'; | ||
import './create-wallet.scss'; | ||
|
||
type TProps = { | ||
is_dark_mode_on: boolean; | ||
should_show_fiat: boolean; | ||
}; | ||
|
||
const CreateWalletWrapper = ({ is_dark_mode_on, should_show_fiat }: TProps) => { | ||
const { wallet_store } = useStores(); | ||
|
||
React.useEffect(() => { | ||
wallet_store.onMount(); | ||
}, []); | ||
|
||
const wallets = should_show_fiat ? wallet_store.wallet_provider.fiat_wallets : wallet_store.wallet_provider.wallets; | ||
|
||
return <CreateWallet is_dark_mode_on={is_dark_mode_on} should_show_fiat={should_show_fiat} wallets={wallets} />; | ||
}; | ||
|
||
export default observer(CreateWalletWrapper); |
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,46 @@ | ||
type CryptoWalletMapping = { | ||
[key: string]: string; | ||
}; | ||
|
||
export const crypto_wallets_mapping: CryptoWalletMapping = { | ||
BTC: 'bitcoin', | ||
ETH: 'ethereum', | ||
LTC: 'litecoin', | ||
USDT: 'tether', | ||
USDC: 'usd_coin', | ||
}; | ||
|
||
export const built_in_wallets = ['deriv_p2p', 'payment_agent']; | ||
|
||
export const e_wallets = [ | ||
'airtm', | ||
'Fasapay', | ||
'Jeton', | ||
'Boleto', | ||
'Neteller', | ||
'PayLivre', | ||
'paysafecard', | ||
'Onlinenaira', | ||
'PerfectMoney', | ||
'Skrill', | ||
'Sticpay', | ||
'Astropay', | ||
'WechatPay', | ||
'Webmoney', | ||
'Beyonic', | ||
'1foryou', | ||
'Advcash', | ||
]; | ||
|
||
export const bankwire = [ | ||
'InstantBankTransfer', | ||
'Paytrust88', | ||
'Nganluong', | ||
'Help2pay', | ||
'Zingpay', | ||
'Trustly', | ||
'Oxxo', | ||
'Spei', | ||
]; | ||
|
||
export const credit_debit_card = ['CreditCards']; |
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,16 +1,19 @@ | ||
import ConfigStore from './config-store'; | ||
import WalletStore from './wallet-store'; | ||
|
||
export default class RootStore { | ||
public config: ConfigStore; | ||
public ws: unknown; | ||
public client: any; | ||
public common: any; | ||
public ui: any; | ||
public wallet_store: WalletStore; | ||
|
||
public constructor(core_store: any) { | ||
this.config = new ConfigStore(this); | ||
this.client = core_store.client; | ||
this.common = core_store.common; | ||
this.ui = core_store.ui; | ||
this.wallet_store = new WalletStore(this); | ||
} | ||
} |
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,92 @@ | ||
import { action, observable, computed } from 'mobx'; | ||
import { WS } from '@deriv/shared'; | ||
import { localize } from '@deriv/translations'; | ||
import BaseStore from './base-store'; | ||
import { | ||
crypto_wallets_mapping, | ||
built_in_wallets, | ||
e_wallets, | ||
bankwire, | ||
credit_debit_card, | ||
} from 'Constants/wallet-types'; | ||
|
||
type TWalletProvider = { | ||
fiat_wallets: { getTitle: () => string; content: string[]; popover_text: () => string }[]; | ||
wallets: { getTitle: () => string; content: string[]; popover_text: () => string }[]; | ||
}; | ||
export default class WalletStore extends BaseStore { | ||
@observable | ||
account_types: any; | ||
|
||
@computed | ||
get wallet_names() { | ||
return this.account_types?.wallet; | ||
} | ||
|
||
@computed | ||
get fiat_currencies() { | ||
return this.wallet_names?.fiat?.currencies.map((currency: string) => currency.toLowerCase()); | ||
} | ||
|
||
@computed | ||
get crypto_wallets() { | ||
return this.wallet_names?.crypto?.currencies.map((currency: string) => crypto_wallets_mapping[currency]); | ||
} | ||
|
||
@computed | ||
get wallet_provider(): TWalletProvider { | ||
const fiat_wallets = [ | ||
{ getTitle: () => localize('E-wallets'), content: e_wallets, popover_text: () => '' }, | ||
{ getTitle: () => localize('Bankwire'), content: bankwire, popover_text: () => '' }, | ||
{ getTitle: () => localize('Credit/Debit card'), content: credit_debit_card, popover_text: () => '' }, | ||
]; | ||
|
||
const wallets = [ | ||
{ | ||
getTitle: () => localize('Fiat currency wallets'), | ||
content: this.fiat_currencies, | ||
popover_text: () => localize('***'), | ||
}, | ||
{ | ||
getTitle: () => localize('Cryptocurrency wallets'), | ||
content: this.crypto_wallets, | ||
popover_text: () => '', | ||
}, | ||
{ | ||
getTitle: () => localize('Deriv P2P and Payment agents wallets'), | ||
content: built_in_wallets, | ||
popover_text: () => '', | ||
}, | ||
]; | ||
|
||
return { | ||
fiat_wallets, | ||
wallets, | ||
}; | ||
} | ||
|
||
@action | ||
onMount() { | ||
this.getWalletNames(); | ||
} | ||
|
||
@action.bound | ||
setAccountTypes(data: any) { | ||
this.account_types = data; | ||
} | ||
|
||
@action.bound | ||
async getWalletNames() { | ||
if (this.wallet_names) return; | ||
const response = await WS.authorized.storage.send({ | ||
get_account_types: 1, | ||
}); | ||
|
||
if (response) this.setAccountTypes(response.get_account_types); | ||
} | ||
|
||
@action | ||
onUnmount() { | ||
this.account_types = null; | ||
} | ||
} |
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,7 +1,9 @@ | ||
import ConfigStore from 'Stores/config-store'; | ||
import WalletStore from 'Stores/wallet-store'; | ||
|
||
export type TRootStore = { | ||
ui: any; | ||
client: any; | ||
config: ConfigStore; | ||
wallet_store: WalletStore; | ||
}; |