aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/components/payment_method_dropdown.tsx
diff options
context:
space:
mode:
authorFrancesco Agosti <francesco.agosti93@gmail.com>2018-11-09 08:29:34 +0800
committerGitHub <noreply@github.com>2018-11-09 08:29:34 +0800
commit3eac119399d3e2729ce65f748d9fb31207ac2540 (patch)
tree558aa4bb76eae3418cf411fcfba089ef8edf19ef /packages/instant/src/components/payment_method_dropdown.tsx
parent117e2f583ff44bdb63340a2134edea0f3ecb77b3 (diff)
parentcd44470a29c48275e6a2a4bba42734d8f900d387 (diff)
downloaddexon-sol-tools-3eac119399d3e2729ce65f748d9fb31207ac2540.tar.gz
dexon-sol-tools-3eac119399d3e2729ce65f748d9fb31207ac2540.tar.zst
dexon-sol-tools-3eac119399d3e2729ce65f748d9fb31207ac2540.zip
Merge pull request #1230 from 0xProject/feature/instant/dropdown-ui
[instant] Dropdown Component Skeleton
Diffstat (limited to 'packages/instant/src/components/payment_method_dropdown.tsx')
-rw-r--r--packages/instant/src/components/payment_method_dropdown.tsx44
1 files changed, 44 insertions, 0 deletions
diff --git a/packages/instant/src/components/payment_method_dropdown.tsx b/packages/instant/src/components/payment_method_dropdown.tsx
new file mode 100644
index 000000000..bdce2a49d
--- /dev/null
+++ b/packages/instant/src/components/payment_method_dropdown.tsx
@@ -0,0 +1,44 @@
+import { BigNumber } from '@0x/utils';
+import copy from 'copy-to-clipboard';
+import * as React from 'react';
+
+import { Network } from '../types';
+import { etherscanUtil } from '../util/etherscan';
+import { format } from '../util/format';
+
+import { Dropdown, DropdownItemConfig } from './ui/dropdown';
+
+export interface PaymentMethodDropdownProps {
+ accountAddress: string;
+ accountEthBalanceInWei?: BigNumber;
+ network: Network;
+}
+
+export class PaymentMethodDropdown extends React.Component<PaymentMethodDropdownProps> {
+ public render(): React.ReactNode {
+ const { accountAddress, accountEthBalanceInWei } = this.props;
+ const value = format.ethAddress(accountAddress);
+ const label = format.ethBaseAmount(accountEthBalanceInWei, 4, '') as string;
+ return <Dropdown value={value} label={label} items={this._getDropdownItemConfigs()} />;
+ }
+ private readonly _getDropdownItemConfigs = (): DropdownItemConfig[] => {
+ const viewOnEtherscan = {
+ text: 'View on Etherscan',
+ onClick: this._handleEtherscanClick,
+ };
+ const copyAddressToClipboard = {
+ text: 'Copy address to clipboard',
+ onClick: this._handleCopyToClipboardClick,
+ };
+ return [viewOnEtherscan, copyAddressToClipboard];
+ };
+ private readonly _handleEtherscanClick = (): void => {
+ const { accountAddress, network } = this.props;
+ const etherscanUrl = etherscanUtil.getEtherScanEthAddressIfExists(accountAddress, network);
+ window.open(etherscanUrl, '_blank');
+ };
+ private readonly _handleCopyToClipboardClick = (): void => {
+ const { accountAddress } = this.props;
+ copy(accountAddress);
+ };
+}