pwc-sdk-wallet 0.7.2 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +369 -0
- package/dist/components/ConnectionModal.d.ts +14 -0
- package/dist/components/ConnectionModal.js +206 -0
- package/dist/components/DAppBrowser.d.ts +11 -0
- package/dist/components/DAppBrowser.js +266 -0
- package/dist/components/TransactionModal.d.ts +9 -0
- package/dist/components/TransactionModal.js +184 -0
- package/dist/connectors/PWCWalletConnector.d.ts +107 -0
- package/dist/connectors/PWCWalletConnector.js +195 -0
- package/dist/hooks/usePWCWallet.d.ts +23 -0
- package/dist/hooks/usePWCWallet.js +140 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +25 -1
- package/dist/services/BrowserProviderService.d.ts +87 -0
- package/dist/services/BrowserProviderService.js +284 -0
- package/dist/services/MessageBridgeService.d.ts +72 -0
- package/dist/services/MessageBridgeService.js +142 -0
- package/dist/services/TransactionHandler.d.ts +83 -0
- package/dist/services/TransactionHandler.js +179 -0
- package/dist/utils/wagmi-config.d.ts +12 -0
- package/dist/utils/wagmi-config.js +21 -0
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -55,6 +55,15 @@ A comprehensive, secure, and user-friendly wallet SDK for React Native applicati
|
|
|
55
55
|
- [Validate QR Code](#validate-qr-code)
|
|
56
56
|
- [Generate EIP-681 Compatible Address QR (for Metamask, Binance, Trust Wallet)](#generate-eip-681-compatible-address-qr-for-metamask-binance-trust-wallet)
|
|
57
57
|
|
|
58
|
+
### 🌐 DApp Browser Integration
|
|
59
|
+
- [DApp Browser Overview](#dapp-browser-overview)
|
|
60
|
+
- [Quick Start](#dapp-browser-quick-start)
|
|
61
|
+
- [Components](#dapp-browser-components)
|
|
62
|
+
- [Services](#dapp-browser-services)
|
|
63
|
+
- [Wagmi Integration](#wagmi-integration)
|
|
64
|
+
- [Hooks](#dapp-browser-hooks)
|
|
65
|
+
- [Examples](#dapp-browser-examples)
|
|
66
|
+
|
|
58
67
|
### 🖼️ NFT Functionality
|
|
59
68
|
- [Get NFT Details](#get-nft-details)
|
|
60
69
|
- [Get NFT Balance](#get-nft-balance)
|
|
@@ -693,6 +702,349 @@ console.log('Transaction History:', history);
|
|
|
693
702
|
// Returns array of: { hash, from, to, blockNumber, timestamp, type }
|
|
694
703
|
```
|
|
695
704
|
|
|
705
|
+
## 🌐 DApp Browser Integration with Wagmi
|
|
706
|
+
|
|
707
|
+
The PWC Wallet SDK provides a complete DApp Browser integration with **Wagmi support**, ensuring that PWC Wallet appears as a connection option in **all dApps** that use Wagmi, ConnectKit, or RainbowKit. This integration follows the same patterns as popular wallets like MetaMask Mobile, Trust Wallet, and Rainbow Wallet.
|
|
708
|
+
|
|
709
|
+
### 🎯 Key Benefits
|
|
710
|
+
|
|
711
|
+
- **Universal dApp Compatibility** - PWC Wallet appears in ALL dApps using Wagmi
|
|
712
|
+
- **One-Click Integration** - Simple setup with `createWagmiConfig`
|
|
713
|
+
- **Built-in WebView Browser** - Complete browser with navigation controls
|
|
714
|
+
- **Automatic Provider Injection** - PWC Wallet provider automatically injected
|
|
715
|
+
- **Transaction Approval UI** - Beautiful transaction approval modals
|
|
716
|
+
- **Connection Approval UI** - dApp connection approval modals
|
|
717
|
+
- **Multi-chain Support** - Support for Ethereum and other EVM chains
|
|
718
|
+
- **Security Features** - Transaction validation and user confirmation
|
|
719
|
+
|
|
720
|
+
### 🚀 Quick Start (Wagmi Integration)
|
|
721
|
+
|
|
722
|
+
```typescript
|
|
723
|
+
import React from 'react';
|
|
724
|
+
import { WagmiConfig } from 'wagmi';
|
|
725
|
+
import { DAppBrowser, createWagmiConfig } from 'pwc-wallet-sdk';
|
|
726
|
+
|
|
727
|
+
const WalletApp = () => {
|
|
728
|
+
const vault = new Vault(); // Your vault instance
|
|
729
|
+
|
|
730
|
+
// Create Wagmi config with PWC Wallet connector
|
|
731
|
+
const wagmiConfig = createWagmiConfig({
|
|
732
|
+
vault: vault,
|
|
733
|
+
pwcWalletName: 'PWC Wallet',
|
|
734
|
+
pwcWalletIcon: 'https://pwc-wallet.com/icon.png'
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
return (
|
|
738
|
+
<WagmiConfig config={wagmiConfig}>
|
|
739
|
+
<DAppBrowser
|
|
740
|
+
vault={vault}
|
|
741
|
+
initialUrl="https://paywithcrypto.io/"
|
|
742
|
+
onTransaction={(transaction) => {
|
|
743
|
+
console.log('Transaction requested:', transaction);
|
|
744
|
+
}}
|
|
745
|
+
onConnection={(dAppInfo) => {
|
|
746
|
+
console.log('Connection requested:', dAppInfo);
|
|
747
|
+
}}
|
|
748
|
+
onError={(error) => {
|
|
749
|
+
console.error('Browser error:', error);
|
|
750
|
+
}}
|
|
751
|
+
/>
|
|
752
|
+
</WagmiConfig>
|
|
753
|
+
);
|
|
754
|
+
};
|
|
755
|
+
```
|
|
756
|
+
|
|
757
|
+
### 🎯 What This Achieves
|
|
758
|
+
|
|
759
|
+
With this setup, PWC Wallet will appear as a connection option in:
|
|
760
|
+
|
|
761
|
+
- ✅ **PancakeSwap** - "Connect Wallet" → PWC Wallet option
|
|
762
|
+
- ✅ **Uniswap** - "Connect Wallet" → PWC Wallet option
|
|
763
|
+
- ✅ **OpenSea** - "Connect Wallet" → PWC Wallet option
|
|
764
|
+
- ✅ **All dApps using Wagmi** - "Connect Wallet" → PWC Wallet option
|
|
765
|
+
- ✅ **All dApps using ConnectKit** - "Connect Wallet" → PWC Wallet option
|
|
766
|
+
- ✅ **All dApps using RainbowKit** - "Connect Wallet" → PWC Wallet option
|
|
767
|
+
|
|
768
|
+
### DApp Browser Components
|
|
769
|
+
|
|
770
|
+
#### DAppBrowser
|
|
771
|
+
|
|
772
|
+
The main component that provides a complete WebView browser with PWC Wallet integration. **Must be wrapped with WagmiConfig for universal dApp compatibility.**
|
|
773
|
+
|
|
774
|
+
```typescript
|
|
775
|
+
import { WagmiConfig } from 'wagmi';
|
|
776
|
+
import { DAppBrowser, createWagmiConfig } from 'pwc-wallet-sdk';
|
|
777
|
+
|
|
778
|
+
// Create Wagmi config for universal dApp compatibility
|
|
779
|
+
const wagmiConfig = createWagmiConfig({
|
|
780
|
+
vault: vault,
|
|
781
|
+
pwcWalletName: 'PWC Wallet'
|
|
782
|
+
});
|
|
783
|
+
|
|
784
|
+
<WagmiConfig config={wagmiConfig}>
|
|
785
|
+
<DAppBrowser
|
|
786
|
+
vault={vault}
|
|
787
|
+
initialUrl="https://paywithcrypto.io/"
|
|
788
|
+
onTransaction={handleTransaction}
|
|
789
|
+
onConnection={handleConnection}
|
|
790
|
+
onError={handleError}
|
|
791
|
+
/>
|
|
792
|
+
</WagmiConfig>
|
|
793
|
+
```
|
|
794
|
+
|
|
795
|
+
#### TransactionModal
|
|
796
|
+
|
|
797
|
+
A modal component for approving/rejecting transactions.
|
|
798
|
+
|
|
799
|
+
```typescript
|
|
800
|
+
import { TransactionModal } from 'pwc-wallet-sdk';
|
|
801
|
+
|
|
802
|
+
<TransactionModal
|
|
803
|
+
visible={showTransactionModal}
|
|
804
|
+
transaction={pendingTransaction}
|
|
805
|
+
onApprove={handleApprove}
|
|
806
|
+
onReject={handleReject}
|
|
807
|
+
/>
|
|
808
|
+
```
|
|
809
|
+
|
|
810
|
+
#### ConnectionModal
|
|
811
|
+
|
|
812
|
+
A modal component for approving/rejecting dApp connections.
|
|
813
|
+
|
|
814
|
+
```typescript
|
|
815
|
+
import { ConnectionModal } from 'pwc-wallet-sdk';
|
|
816
|
+
|
|
817
|
+
<ConnectionModal
|
|
818
|
+
visible={showConnectionModal}
|
|
819
|
+
dAppInfo={pendingConnection}
|
|
820
|
+
onApprove={handleApprove}
|
|
821
|
+
onReject={handleReject}
|
|
822
|
+
/>
|
|
823
|
+
```
|
|
824
|
+
|
|
825
|
+
### DApp Browser Services
|
|
826
|
+
|
|
827
|
+
#### BrowserProviderService
|
|
828
|
+
|
|
829
|
+
Handles the injection of PWC Wallet provider into WebView and processes dApp requests.
|
|
830
|
+
|
|
831
|
+
```typescript
|
|
832
|
+
import { BrowserProviderService } from 'pwc-wallet-sdk';
|
|
833
|
+
|
|
834
|
+
const browserProviderService = new BrowserProviderService(vault);
|
|
835
|
+
const providerScript = browserProviderService.injectPWCWalletProvider();
|
|
836
|
+
```
|
|
837
|
+
|
|
838
|
+
#### MessageBridgeService
|
|
839
|
+
|
|
840
|
+
Manages communication between WebView and React Native.
|
|
841
|
+
|
|
842
|
+
```typescript
|
|
843
|
+
import { MessageBridgeService } from 'pwc-wallet-sdk';
|
|
844
|
+
|
|
845
|
+
const messageBridgeService = new MessageBridgeService();
|
|
846
|
+
messageBridgeService.setWebViewRef(webViewRef.current);
|
|
847
|
+
```
|
|
848
|
+
|
|
849
|
+
#### TransactionHandler
|
|
850
|
+
|
|
851
|
+
Processes and validates transactions.
|
|
852
|
+
|
|
853
|
+
```typescript
|
|
854
|
+
import { TransactionHandler } from 'pwc-wallet-sdk';
|
|
855
|
+
|
|
856
|
+
const transactionHandler = new TransactionHandler(vault);
|
|
857
|
+
const details = await transactionHandler.processTransaction(transaction);
|
|
858
|
+
```
|
|
859
|
+
|
|
860
|
+
### 🔌 Wagmi Integration (Core Feature)
|
|
861
|
+
|
|
862
|
+
#### PWCWalletConnector
|
|
863
|
+
|
|
864
|
+
The **core component** that makes PWC Wallet appear in all dApps. This connector integrates PWC Wallet with the Wagmi ecosystem, ensuring universal compatibility.
|
|
865
|
+
|
|
866
|
+
```typescript
|
|
867
|
+
import { PWCWalletConnector, createWagmiConfig } from 'pwc-wallet-sdk';
|
|
868
|
+
|
|
869
|
+
// Create PWC Wallet connector
|
|
870
|
+
const connector = new PWCWalletConnector({
|
|
871
|
+
vault: vault,
|
|
872
|
+
name: 'PWC Wallet',
|
|
873
|
+
icon: 'https://pwc-wallet.com/icon.png'
|
|
874
|
+
});
|
|
875
|
+
|
|
876
|
+
// Create complete Wagmi config
|
|
877
|
+
const config = createWagmiConfig({
|
|
878
|
+
vault: vault,
|
|
879
|
+
appName: 'PWC Wallet',
|
|
880
|
+
pwcWalletName: 'PWC Wallet',
|
|
881
|
+
pwcWalletIcon: 'https://pwc-wallet.com/icon.png'
|
|
882
|
+
});
|
|
883
|
+
```
|
|
884
|
+
|
|
885
|
+
#### Why This Matters
|
|
886
|
+
|
|
887
|
+
- **Universal Compatibility** - PWC Wallet appears in ALL dApps using Wagmi
|
|
888
|
+
- **No dApp Changes Required** - dApps don't need to add PWC Wallet manually
|
|
889
|
+
- **Industry Standard** - Follows the same pattern as MetaMask, WalletConnect
|
|
890
|
+
- **Future-Proof** - Works with any new dApp that uses Wagmi
|
|
891
|
+
|
|
892
|
+
### DApp Browser Hooks
|
|
893
|
+
|
|
894
|
+
#### usePWCWallet
|
|
895
|
+
|
|
896
|
+
A React hook that provides easy access to PWC Wallet functionality.
|
|
897
|
+
|
|
898
|
+
```typescript
|
|
899
|
+
import { usePWCWallet } from 'pwc-wallet-sdk';
|
|
900
|
+
|
|
901
|
+
const {
|
|
902
|
+
accounts,
|
|
903
|
+
currentAccount,
|
|
904
|
+
isConnected,
|
|
905
|
+
connect,
|
|
906
|
+
disconnect,
|
|
907
|
+
sendTransaction,
|
|
908
|
+
signMessage,
|
|
909
|
+
isLoading,
|
|
910
|
+
error
|
|
911
|
+
} = usePWCWallet({ vault });
|
|
912
|
+
```
|
|
913
|
+
|
|
914
|
+
### DApp Browser Examples
|
|
915
|
+
|
|
916
|
+
#### Complete Wallet App with Wagmi Integration
|
|
917
|
+
|
|
918
|
+
```typescript
|
|
919
|
+
import React, { useState } from 'react';
|
|
920
|
+
import { View, Text, TouchableOpacity } from 'react-native';
|
|
921
|
+
import { WagmiConfig } from 'wagmi';
|
|
922
|
+
import { DAppBrowser, usePWCWallet, Vault, createWagmiConfig } from 'pwc-wallet-sdk';
|
|
923
|
+
|
|
924
|
+
const WalletApp = () => {
|
|
925
|
+
const [activeTab, setActiveTab] = useState<'wallet' | 'browser'>('wallet');
|
|
926
|
+
const vault = new Vault(); // Your vault instance
|
|
927
|
+
|
|
928
|
+
// Create Wagmi config for universal dApp compatibility
|
|
929
|
+
const wagmiConfig = createWagmiConfig({
|
|
930
|
+
vault: vault,
|
|
931
|
+
pwcWalletName: 'PWC Wallet',
|
|
932
|
+
pwcWalletIcon: 'https://pwc-wallet.com/icon.png'
|
|
933
|
+
});
|
|
934
|
+
|
|
935
|
+
const { accounts, currentAccount, isConnected, connect, disconnect } = usePWCWallet({ vault });
|
|
936
|
+
|
|
937
|
+
if (activeTab === 'browser') {
|
|
938
|
+
return (
|
|
939
|
+
<WagmiConfig config={wagmiConfig}>
|
|
940
|
+
<DAppBrowser
|
|
941
|
+
vault={vault}
|
|
942
|
+
initialUrl="https://paywithcrypto.io/"
|
|
943
|
+
onTransaction={(transaction) => {
|
|
944
|
+
console.log('Transaction:', transaction);
|
|
945
|
+
}}
|
|
946
|
+
onConnection={(dAppInfo) => {
|
|
947
|
+
console.log('Connection:', dAppInfo);
|
|
948
|
+
}}
|
|
949
|
+
/>
|
|
950
|
+
</WagmiConfig>
|
|
951
|
+
);
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
return (
|
|
955
|
+
<View>
|
|
956
|
+
<Text>PWC Wallet</Text>
|
|
957
|
+
{isConnected ? (
|
|
958
|
+
<View>
|
|
959
|
+
<Text>Connected: {currentAccount}</Text>
|
|
960
|
+
<TouchableOpacity onPress={() => setActiveTab('browser')}>
|
|
961
|
+
<Text>Open Browser</Text>
|
|
962
|
+
</TouchableOpacity>
|
|
963
|
+
<TouchableOpacity onPress={disconnect}>
|
|
964
|
+
<Text>Disconnect</Text>
|
|
965
|
+
</TouchableOpacity>
|
|
966
|
+
</View>
|
|
967
|
+
) : (
|
|
968
|
+
<TouchableOpacity onPress={connect}>
|
|
969
|
+
<Text>Connect Wallet</Text>
|
|
970
|
+
</TouchableOpacity>
|
|
971
|
+
)}
|
|
972
|
+
</View>
|
|
973
|
+
);
|
|
974
|
+
};
|
|
975
|
+
```
|
|
976
|
+
|
|
977
|
+
#### Real-World Example: PancakeSwap Integration
|
|
978
|
+
|
|
979
|
+
```typescript
|
|
980
|
+
import React from 'react';
|
|
981
|
+
import { WagmiConfig } from 'wagmi';
|
|
982
|
+
import { DAppBrowser, createWagmiConfig } from 'pwc-wallet-sdk';
|
|
983
|
+
|
|
984
|
+
const PancakeSwapExample = () => {
|
|
985
|
+
const vault = new Vault();
|
|
986
|
+
|
|
987
|
+
const wagmiConfig = createWagmiConfig({
|
|
988
|
+
vault: vault,
|
|
989
|
+
pwcWalletName: 'PWC Wallet'
|
|
990
|
+
});
|
|
991
|
+
|
|
992
|
+
return (
|
|
993
|
+
<WagmiConfig config={wagmiConfig}>
|
|
994
|
+
<DAppBrowser
|
|
995
|
+
vault={vault}
|
|
996
|
+
initialUrl="https://pancakeswap.finance/"
|
|
997
|
+
onTransaction={(transaction) => {
|
|
998
|
+
console.log('PancakeSwap transaction:', transaction);
|
|
999
|
+
}}
|
|
1000
|
+
onConnection={(dAppInfo) => {
|
|
1001
|
+
console.log('PancakeSwap connection:', dAppInfo);
|
|
1002
|
+
}}
|
|
1003
|
+
/>
|
|
1004
|
+
</WagmiConfig>
|
|
1005
|
+
);
|
|
1006
|
+
};
|
|
1007
|
+
```
|
|
1008
|
+
|
|
1009
|
+
**Result:** When user clicks "Connect Wallet" on PancakeSwap, they will see "PWC Wallet" as an option! 🎯
|
|
1010
|
+
|
|
1011
|
+
### 🎯 Summary: Universal dApp Compatibility
|
|
1012
|
+
|
|
1013
|
+
The PWC Wallet SDK with Wagmi integration provides **universal dApp compatibility**:
|
|
1014
|
+
|
|
1015
|
+
#### ✅ **Works with ALL dApps:**
|
|
1016
|
+
- **PancakeSwap** - "Connect Wallet" → PWC Wallet option
|
|
1017
|
+
- **Uniswap** - "Connect Wallet" → PWC Wallet option
|
|
1018
|
+
- **OpenSea** - "Connect Wallet" → PWC Wallet option
|
|
1019
|
+
- **Aave** - "Connect Wallet" → PWC Wallet option
|
|
1020
|
+
- **Compound** - "Connect Wallet" → PWC Wallet option
|
|
1021
|
+
- **Any dApp using Wagmi** - "Connect Wallet" → PWC Wallet option
|
|
1022
|
+
|
|
1023
|
+
#### ✅ **One Setup, Universal Access:**
|
|
1024
|
+
```typescript
|
|
1025
|
+
// Mobile dev chỉ cần setup 1 lần
|
|
1026
|
+
const wagmiConfig = createWagmiConfig({
|
|
1027
|
+
vault: vault,
|
|
1028
|
+
pwcWalletName: 'PWC Wallet'
|
|
1029
|
+
});
|
|
1030
|
+
|
|
1031
|
+
<WagmiConfig config={wagmiConfig}>
|
|
1032
|
+
<DAppBrowser vault={vault} />
|
|
1033
|
+
</WagmiConfig>
|
|
1034
|
+
```
|
|
1035
|
+
|
|
1036
|
+
#### ✅ **No dApp Changes Required:**
|
|
1037
|
+
- dApps don't need to add PWC Wallet manually
|
|
1038
|
+
- Works with existing dApp code
|
|
1039
|
+
- Follows industry standards (MetaMask, WalletConnect)
|
|
1040
|
+
|
|
1041
|
+
#### ✅ **No WalletConnect Required:**
|
|
1042
|
+
- PWC Wallet uses built-in browser (WebView)
|
|
1043
|
+
- No need for `projectId` or WalletConnect bridge
|
|
1044
|
+
- Direct connection without external services
|
|
1045
|
+
|
|
1046
|
+
For detailed documentation, see [DApp Browser Integration Guide](./docs/DAPP_BROWSER_INTEGRATION.md).
|
|
1047
|
+
|
|
696
1048
|
### NFT Types and Interfaces
|
|
697
1049
|
Complete TypeScript interfaces for NFT functionality.
|
|
698
1050
|
|
|
@@ -1070,10 +1422,27 @@ console.log('ERC-1155 transfer gas:', erc1155TransferGas.toString());
|
|
|
1070
1422
|
|
|
1071
1423
|
## Installation
|
|
1072
1424
|
|
|
1425
|
+
### Basic Installation
|
|
1426
|
+
|
|
1073
1427
|
```bash
|
|
1074
1428
|
npm install pwc-wallet-sdk
|
|
1075
1429
|
```
|
|
1076
1430
|
|
|
1431
|
+
### DApp Browser Dependencies
|
|
1432
|
+
|
|
1433
|
+
For DApp Browser functionality with universal dApp compatibility:
|
|
1434
|
+
|
|
1435
|
+
```bash
|
|
1436
|
+
npm install pwc-wallet-sdk react-native-webview wagmi connectkit
|
|
1437
|
+
```
|
|
1438
|
+
|
|
1439
|
+
**Required Dependencies:**
|
|
1440
|
+
- `react-native-webview` - For WebView browser functionality
|
|
1441
|
+
- `wagmi` - For universal dApp compatibility
|
|
1442
|
+
- `connectkit` - For modern wallet connection UI
|
|
1443
|
+
|
|
1444
|
+
**Note:** These are peer dependencies. Mobile developers need to install them to use the DApp Browser features.
|
|
1445
|
+
|
|
1077
1446
|
## Quick Start
|
|
1078
1447
|
|
|
1079
1448
|
### 1. Basic Wallet Creation
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface DAppInfo {
|
|
3
|
+
name: string;
|
|
4
|
+
description: string;
|
|
5
|
+
url: string;
|
|
6
|
+
icons: string[];
|
|
7
|
+
}
|
|
8
|
+
export interface ConnectionModalProps {
|
|
9
|
+
visible: boolean;
|
|
10
|
+
dAppInfo: DAppInfo | null;
|
|
11
|
+
onApprove: () => void;
|
|
12
|
+
onReject: () => void;
|
|
13
|
+
}
|
|
14
|
+
export declare const ConnectionModal: React.FC<ConnectionModalProps>;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ConnectionModal = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const react_native_1 = require("react-native");
|
|
9
|
+
const ConnectionModal = ({ visible, dAppInfo, onApprove, onReject, }) => {
|
|
10
|
+
if (!dAppInfo)
|
|
11
|
+
return null;
|
|
12
|
+
const handleApprove = () => {
|
|
13
|
+
react_native_1.Alert.alert('Confirm Connection', `Are you sure you want to connect to ${dAppInfo.name}?`, [
|
|
14
|
+
{ text: 'Cancel', style: 'cancel' },
|
|
15
|
+
{ text: 'Connect', onPress: onApprove, style: 'default' },
|
|
16
|
+
]);
|
|
17
|
+
};
|
|
18
|
+
const handleReject = () => {
|
|
19
|
+
react_native_1.Alert.alert('Reject Connection', `Are you sure you want to reject the connection to ${dAppInfo.name}?`, [
|
|
20
|
+
{ text: 'Cancel', style: 'cancel' },
|
|
21
|
+
{ text: 'Reject', onPress: onReject, style: 'destructive' },
|
|
22
|
+
]);
|
|
23
|
+
};
|
|
24
|
+
return (react_1.default.createElement(react_native_1.Modal, { visible: visible, animationType: "slide", transparent: true, onRequestClose: onReject },
|
|
25
|
+
react_1.default.createElement(react_native_1.View, { style: styles.overlay },
|
|
26
|
+
react_1.default.createElement(react_native_1.View, { style: styles.modalContainer },
|
|
27
|
+
react_1.default.createElement(react_native_1.View, { style: styles.header },
|
|
28
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.title }, "Connect to dApp"),
|
|
29
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.subtitle }, "Review connection request")),
|
|
30
|
+
react_1.default.createElement(react_native_1.ScrollView, { style: styles.content },
|
|
31
|
+
react_1.default.createElement(react_native_1.View, { style: styles.dAppInfo },
|
|
32
|
+
dAppInfo.icons && dAppInfo.icons.length > 0 && (react_1.default.createElement(react_native_1.Image, { source: { uri: dAppInfo.icons[0] }, style: styles.dAppIcon })),
|
|
33
|
+
react_1.default.createElement(react_native_1.View, { style: styles.dAppDetails },
|
|
34
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.dAppName }, dAppInfo.name),
|
|
35
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.dAppUrl }, dAppInfo.url))),
|
|
36
|
+
react_1.default.createElement(react_native_1.View, { style: styles.section },
|
|
37
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.sectionTitle }, "Description"),
|
|
38
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.description }, dAppInfo.description)),
|
|
39
|
+
react_1.default.createElement(react_native_1.View, { style: styles.section },
|
|
40
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.sectionTitle }, "Permissions"),
|
|
41
|
+
react_1.default.createElement(react_native_1.View, { style: styles.permissionItem },
|
|
42
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.permissionText }, "\u2022 View account address")),
|
|
43
|
+
react_1.default.createElement(react_native_1.View, { style: styles.permissionItem },
|
|
44
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.permissionText }, "\u2022 Request transaction approval")),
|
|
45
|
+
react_1.default.createElement(react_native_1.View, { style: styles.permissionItem },
|
|
46
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.permissionText }, "\u2022 Request message signing"))),
|
|
47
|
+
react_1.default.createElement(react_native_1.View, { style: styles.section },
|
|
48
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.sectionTitle }, "Network"),
|
|
49
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.network }, "Ethereum Mainnet")),
|
|
50
|
+
react_1.default.createElement(react_native_1.View, { style: styles.warningSection },
|
|
51
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.warningTitle }, "\u26A0\uFE0F Security Notice"),
|
|
52
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.warningText }, "Only connect to dApps you trust. This connection will allow the dApp to:"),
|
|
53
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.warningText }, "\u2022 View your wallet address"),
|
|
54
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.warningText }, "\u2022 Request transaction approvals"),
|
|
55
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.warningText }, "\u2022 Request message signatures"))),
|
|
56
|
+
react_1.default.createElement(react_native_1.View, { style: styles.footer },
|
|
57
|
+
react_1.default.createElement(react_native_1.TouchableOpacity, { style: styles.rejectButton, onPress: handleReject },
|
|
58
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.rejectButtonText }, "Reject")),
|
|
59
|
+
react_1.default.createElement(react_native_1.TouchableOpacity, { style: styles.approveButton, onPress: handleApprove },
|
|
60
|
+
react_1.default.createElement(react_native_1.Text, { style: styles.approveButtonText }, "Connect")))))));
|
|
61
|
+
};
|
|
62
|
+
exports.ConnectionModal = ConnectionModal;
|
|
63
|
+
const styles = react_native_1.StyleSheet.create({
|
|
64
|
+
overlay: {
|
|
65
|
+
flex: 1,
|
|
66
|
+
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
67
|
+
justifyContent: 'center',
|
|
68
|
+
alignItems: 'center',
|
|
69
|
+
},
|
|
70
|
+
modalContainer: {
|
|
71
|
+
width: '90%',
|
|
72
|
+
maxHeight: '80%',
|
|
73
|
+
backgroundColor: '#fff',
|
|
74
|
+
borderRadius: 12,
|
|
75
|
+
overflow: 'hidden',
|
|
76
|
+
},
|
|
77
|
+
header: {
|
|
78
|
+
padding: 20,
|
|
79
|
+
borderBottomWidth: 1,
|
|
80
|
+
borderBottomColor: '#e9ecef',
|
|
81
|
+
backgroundColor: '#f8f9fa',
|
|
82
|
+
},
|
|
83
|
+
title: {
|
|
84
|
+
fontSize: 20,
|
|
85
|
+
fontWeight: 'bold',
|
|
86
|
+
color: '#212529',
|
|
87
|
+
textAlign: 'center',
|
|
88
|
+
},
|
|
89
|
+
subtitle: {
|
|
90
|
+
fontSize: 14,
|
|
91
|
+
color: '#6c757d',
|
|
92
|
+
textAlign: 'center',
|
|
93
|
+
marginTop: 4,
|
|
94
|
+
},
|
|
95
|
+
content: {
|
|
96
|
+
flex: 1,
|
|
97
|
+
padding: 20,
|
|
98
|
+
},
|
|
99
|
+
dAppInfo: {
|
|
100
|
+
flexDirection: 'row',
|
|
101
|
+
alignItems: 'center',
|
|
102
|
+
marginBottom: 20,
|
|
103
|
+
padding: 16,
|
|
104
|
+
backgroundColor: '#f8f9fa',
|
|
105
|
+
borderRadius: 8,
|
|
106
|
+
},
|
|
107
|
+
dAppIcon: {
|
|
108
|
+
width: 48,
|
|
109
|
+
height: 48,
|
|
110
|
+
borderRadius: 8,
|
|
111
|
+
marginRight: 12,
|
|
112
|
+
},
|
|
113
|
+
dAppDetails: {
|
|
114
|
+
flex: 1,
|
|
115
|
+
},
|
|
116
|
+
dAppName: {
|
|
117
|
+
fontSize: 18,
|
|
118
|
+
fontWeight: 'bold',
|
|
119
|
+
color: '#212529',
|
|
120
|
+
marginBottom: 4,
|
|
121
|
+
},
|
|
122
|
+
dAppUrl: {
|
|
123
|
+
fontSize: 14,
|
|
124
|
+
color: '#6c757d',
|
|
125
|
+
},
|
|
126
|
+
section: {
|
|
127
|
+
marginBottom: 16,
|
|
128
|
+
},
|
|
129
|
+
sectionTitle: {
|
|
130
|
+
fontSize: 16,
|
|
131
|
+
fontWeight: '600',
|
|
132
|
+
color: '#495057',
|
|
133
|
+
marginBottom: 8,
|
|
134
|
+
},
|
|
135
|
+
description: {
|
|
136
|
+
fontSize: 14,
|
|
137
|
+
color: '#212529',
|
|
138
|
+
lineHeight: 20,
|
|
139
|
+
},
|
|
140
|
+
permissionItem: {
|
|
141
|
+
marginBottom: 4,
|
|
142
|
+
},
|
|
143
|
+
permissionText: {
|
|
144
|
+
fontSize: 14,
|
|
145
|
+
color: '#212529',
|
|
146
|
+
},
|
|
147
|
+
network: {
|
|
148
|
+
fontSize: 14,
|
|
149
|
+
color: '#212529',
|
|
150
|
+
fontWeight: '500',
|
|
151
|
+
},
|
|
152
|
+
warningSection: {
|
|
153
|
+
marginTop: 20,
|
|
154
|
+
padding: 16,
|
|
155
|
+
backgroundColor: '#fff3cd',
|
|
156
|
+
borderRadius: 8,
|
|
157
|
+
borderWidth: 1,
|
|
158
|
+
borderColor: '#ffeaa7',
|
|
159
|
+
},
|
|
160
|
+
warningTitle: {
|
|
161
|
+
fontSize: 16,
|
|
162
|
+
fontWeight: 'bold',
|
|
163
|
+
color: '#856404',
|
|
164
|
+
marginBottom: 8,
|
|
165
|
+
},
|
|
166
|
+
warningText: {
|
|
167
|
+
fontSize: 14,
|
|
168
|
+
color: '#856404',
|
|
169
|
+
lineHeight: 18,
|
|
170
|
+
marginBottom: 4,
|
|
171
|
+
},
|
|
172
|
+
footer: {
|
|
173
|
+
flexDirection: 'row',
|
|
174
|
+
padding: 20,
|
|
175
|
+
borderTopWidth: 1,
|
|
176
|
+
borderTopColor: '#e9ecef',
|
|
177
|
+
},
|
|
178
|
+
rejectButton: {
|
|
179
|
+
flex: 1,
|
|
180
|
+
paddingVertical: 12,
|
|
181
|
+
paddingHorizontal: 20,
|
|
182
|
+
backgroundColor: '#6c757d',
|
|
183
|
+
borderRadius: 8,
|
|
184
|
+
marginRight: 10,
|
|
185
|
+
},
|
|
186
|
+
rejectButtonText: {
|
|
187
|
+
color: '#fff',
|
|
188
|
+
fontSize: 16,
|
|
189
|
+
fontWeight: '600',
|
|
190
|
+
textAlign: 'center',
|
|
191
|
+
},
|
|
192
|
+
approveButton: {
|
|
193
|
+
flex: 1,
|
|
194
|
+
paddingVertical: 12,
|
|
195
|
+
paddingHorizontal: 20,
|
|
196
|
+
backgroundColor: '#007AFF',
|
|
197
|
+
borderRadius: 8,
|
|
198
|
+
marginLeft: 10,
|
|
199
|
+
},
|
|
200
|
+
approveButtonText: {
|
|
201
|
+
color: '#fff',
|
|
202
|
+
fontSize: 16,
|
|
203
|
+
fontWeight: '600',
|
|
204
|
+
textAlign: 'center',
|
|
205
|
+
},
|
|
206
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Vault } from '../Vault';
|
|
3
|
+
export interface DAppBrowserProps {
|
|
4
|
+
vault: Vault;
|
|
5
|
+
initialUrl?: string;
|
|
6
|
+
onTransaction?: (transaction: any) => void;
|
|
7
|
+
onConnection?: (dAppInfo: any) => void;
|
|
8
|
+
onError?: (error: Error) => void;
|
|
9
|
+
style?: any;
|
|
10
|
+
}
|
|
11
|
+
export declare const DAppBrowser: React.FC<DAppBrowserProps>;
|