@reown/appkit-bitcoin-react-native 0.0.0-feat-multichain-20250513175016
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/lib/commonjs/adapter.js +93 -0
- package/lib/commonjs/adapter.js.map +1 -0
- package/lib/commonjs/index.js +13 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/utils/BitcoinApi.js +24 -0
- package/lib/commonjs/utils/BitcoinApi.js.map +1 -0
- package/lib/commonjs/utils/UnitsUtil.js +15 -0
- package/lib/commonjs/utils/UnitsUtil.js.map +1 -0
- package/lib/module/adapter.js +86 -0
- package/lib/module/adapter.js.map +1 -0
- package/lib/module/index.js +3 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/utils/BitcoinApi.js +18 -0
- package/lib/module/utils/BitcoinApi.js.map +1 -0
- package/lib/module/utils/UnitsUtil.js +9 -0
- package/lib/module/utils/UnitsUtil.js.map +1 -0
- package/lib/typescript/adapter.d.ts +15 -0
- package/lib/typescript/adapter.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +3 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/utils/BitcoinApi.d.ts +23 -0
- package/lib/typescript/utils/BitcoinApi.d.ts.map +1 -0
- package/lib/typescript/utils/UnitsUtil.d.ts +5 -0
- package/lib/typescript/utils/UnitsUtil.d.ts.map +1 -0
- package/package.json +54 -0
- package/readme.md +9 -0
- package/src/adapter.ts +100 -0
- package/src/index.tsx +2 -0
- package/src/utils/BitcoinApi.ts +41 -0
- package/src/utils/UnitsUtil.ts +11 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.BitcoinAdapter = void 0;
|
|
7
|
+
var _appkitCommonReactNative = require("@reown/appkit-common-react-native");
|
|
8
|
+
var _BitcoinApi = require("./utils/BitcoinApi");
|
|
9
|
+
var _UnitsUtil = require("./utils/UnitsUtil");
|
|
10
|
+
class BitcoinAdapter extends _appkitCommonReactNative.BlockchainAdapter {
|
|
11
|
+
static supportedNamespace = 'bip122';
|
|
12
|
+
static api = _BitcoinApi.BitcoinApi;
|
|
13
|
+
constructor(configParams) {
|
|
14
|
+
super({
|
|
15
|
+
projectId: configParams.projectId,
|
|
16
|
+
supportedNamespace: BitcoinAdapter.supportedNamespace
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
async getBalance(params) {
|
|
20
|
+
const {
|
|
21
|
+
network,
|
|
22
|
+
address
|
|
23
|
+
} = params;
|
|
24
|
+
if (!this.connector) throw new Error('No active connector');
|
|
25
|
+
if (!network) throw new Error('No network provided');
|
|
26
|
+
const balanceCaipAddress = address || this.getAccounts()?.find(account => account.includes(network.id.toString()));
|
|
27
|
+
const balanceAddress = balanceCaipAddress?.split(':')[2];
|
|
28
|
+
if (!balanceCaipAddress || !balanceAddress) {
|
|
29
|
+
return Promise.resolve({
|
|
30
|
+
amount: '0.00',
|
|
31
|
+
symbol: 'BTC'
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const utxos = await BitcoinAdapter.api.getUTXOs({
|
|
36
|
+
network,
|
|
37
|
+
address: balanceAddress
|
|
38
|
+
});
|
|
39
|
+
const balance = utxos.reduce((acc, utxo) => acc + utxo.value, 0);
|
|
40
|
+
const formattedBalance = _UnitsUtil.UnitsUtil.parseSatoshis(balance.toString(), network);
|
|
41
|
+
this.emit('balanceChanged', {
|
|
42
|
+
namespace: this.getSupportedNamespace(),
|
|
43
|
+
address: balanceCaipAddress,
|
|
44
|
+
balance: {
|
|
45
|
+
amount: formattedBalance,
|
|
46
|
+
symbol: network.nativeCurrency.symbol
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
amount: formattedBalance,
|
|
51
|
+
symbol: network.nativeCurrency.symbol
|
|
52
|
+
};
|
|
53
|
+
} catch (error) {
|
|
54
|
+
return {
|
|
55
|
+
amount: '0.00',
|
|
56
|
+
symbol: 'BTC'
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async switchNetwork(network) {
|
|
61
|
+
if (!this.connector) throw new Error('No active connector');
|
|
62
|
+
const provider = this.connector.getProvider();
|
|
63
|
+
if (!provider) throw new Error('No active provider');
|
|
64
|
+
try {
|
|
65
|
+
await this.connector.switchNetwork(network);
|
|
66
|
+
return;
|
|
67
|
+
} catch (switchError) {
|
|
68
|
+
throw switchError;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
getAccounts() {
|
|
72
|
+
if (!this.connector) throw new Error('No active connector');
|
|
73
|
+
const namespaces = this.connector.getNamespaces();
|
|
74
|
+
return namespaces[this.getSupportedNamespace()]?.accounts;
|
|
75
|
+
}
|
|
76
|
+
disconnect() {
|
|
77
|
+
if (!this.connector) throw new Error('SolanaAdapter:disconnect - No active connector');
|
|
78
|
+
return this.connector.disconnect();
|
|
79
|
+
}
|
|
80
|
+
async request(method, params) {
|
|
81
|
+
if (!this.connector) throw new Error('No active connector');
|
|
82
|
+
const provider = this.connector.getProvider();
|
|
83
|
+
return provider.request({
|
|
84
|
+
method,
|
|
85
|
+
params
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
getSupportedNamespace() {
|
|
89
|
+
return BitcoinAdapter.supportedNamespace;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.BitcoinAdapter = BitcoinAdapter;
|
|
93
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_appkitCommonReactNative","require","_BitcoinApi","_UnitsUtil","BitcoinAdapter","BlockchainAdapter","supportedNamespace","api","BitcoinApi","constructor","configParams","projectId","getBalance","params","network","address","connector","Error","balanceCaipAddress","getAccounts","find","account","includes","id","toString","balanceAddress","split","Promise","resolve","amount","symbol","utxos","getUTXOs","balance","reduce","acc","utxo","value","formattedBalance","UnitsUtil","parseSatoshis","emit","namespace","getSupportedNamespace","nativeCurrency","error","switchNetwork","provider","getProvider","switchError","namespaces","getNamespaces","accounts","disconnect","request","method","exports"],"sourceRoot":"../../src","sources":["adapter.ts"],"mappings":"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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "BitcoinAdapter", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _adapter.BitcoinAdapter;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _adapter = require("./adapter");
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_adapter","require"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.BitcoinApi = void 0;
|
|
7
|
+
const BitcoinApi = exports.BitcoinApi = {
|
|
8
|
+
getUTXOs: async ({
|
|
9
|
+
network,
|
|
10
|
+
address
|
|
11
|
+
}) => {
|
|
12
|
+
const isTestnet = network.caipNetworkId === 'bip122:000000000933ea01ad0ee984209779ba';
|
|
13
|
+
// Make chain dynamic
|
|
14
|
+
|
|
15
|
+
//TODO: Call rpc to get balance
|
|
16
|
+
const url = `https://mempool.space${isTestnet ? '/testnet' : ''}/api/address/${address}/utxo`;
|
|
17
|
+
const response = await fetch(url);
|
|
18
|
+
if (!response.ok) {
|
|
19
|
+
throw new Error(`Failed to fetch UTXOs: ${await response.text()}`);
|
|
20
|
+
}
|
|
21
|
+
return await response.json();
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=BitcoinApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["BitcoinApi","exports","getUTXOs","network","address","isTestnet","caipNetworkId","url","response","fetch","ok","Error","text","json"],"sourceRoot":"../../../src","sources":["utils/BitcoinApi.ts"],"mappings":";;;;;;AAEO,MAAMA,UAAgC,GAAAC,OAAA,CAAAD,UAAA,GAAG;EAC9CE,QAAQ,EAAE,MAAAA,CAAO;IAAEC,OAAO;IAAEC;EAAmC,CAAC,KAAiC;IAC/F,MAAMC,SAAS,GAAGF,OAAO,CAACG,aAAa,KAAK,yCAAyC;IACrF;;IAEA;IACA,MAAMC,GAAG,GAAI,wBAAuBF,SAAS,GAAG,UAAU,GAAG,EAAG,gBAAeD,OAAQ,OAAM;IAC7F,MAAMI,QAAQ,GAAG,MAAMC,KAAK,CAACF,GAAG,CAAC;IAEjC,IAAI,CAACC,QAAQ,CAACE,EAAE,EAAE;MAChB,MAAM,IAAIC,KAAK,CAAE,0BAAyB,MAAMH,QAAQ,CAACI,IAAI,CAAC,CAAE,EAAC,CAAC;IACpE;IAEA,OAAQ,MAAMJ,QAAQ,CAACK,IAAI,CAAC,CAAC;EAC/B;AACF,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UnitsUtil = void 0;
|
|
7
|
+
const UnitsUtil = exports.UnitsUtil = {
|
|
8
|
+
parseSatoshis(amount, network) {
|
|
9
|
+
const value = parseFloat(amount) / 10 ** network.nativeCurrency.decimals;
|
|
10
|
+
return Intl.NumberFormat('en-US', {
|
|
11
|
+
maximumFractionDigits: network.nativeCurrency.decimals
|
|
12
|
+
}).format(value);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=UnitsUtil.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["UnitsUtil","exports","parseSatoshis","amount","network","value","parseFloat","nativeCurrency","decimals","Intl","NumberFormat","maximumFractionDigits","format"],"sourceRoot":"../../../src","sources":["utils/UnitsUtil.ts"],"mappings":";;;;;;AAEO,MAAMA,SAAS,GAAAC,OAAA,CAAAD,SAAA,GAAG;EACvBE,aAAaA,CAACC,MAAc,EAAEC,OAAsB,EAAU;IAC5D,MAAMC,KAAK,GAAGC,UAAU,CAACH,MAAM,CAAC,GAAG,EAAE,IAAIC,OAAO,CAACG,cAAc,CAACC,QAAQ;IAExE,OAAOC,IAAI,CAACC,YAAY,CAAC,OAAO,EAAE;MAChCC,qBAAqB,EAAEP,OAAO,CAACG,cAAc,CAACC;IAChD,CAAC,CAAC,CAACI,MAAM,CAACP,KAAK,CAAC;EAClB;AACF,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { BlockchainAdapter } from '@reown/appkit-common-react-native';
|
|
2
|
+
import { BitcoinApi } from './utils/BitcoinApi';
|
|
3
|
+
import { UnitsUtil } from './utils/UnitsUtil';
|
|
4
|
+
export class BitcoinAdapter extends BlockchainAdapter {
|
|
5
|
+
static supportedNamespace = 'bip122';
|
|
6
|
+
static api = BitcoinApi;
|
|
7
|
+
constructor(configParams) {
|
|
8
|
+
super({
|
|
9
|
+
projectId: configParams.projectId,
|
|
10
|
+
supportedNamespace: BitcoinAdapter.supportedNamespace
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
async getBalance(params) {
|
|
14
|
+
const {
|
|
15
|
+
network,
|
|
16
|
+
address
|
|
17
|
+
} = params;
|
|
18
|
+
if (!this.connector) throw new Error('No active connector');
|
|
19
|
+
if (!network) throw new Error('No network provided');
|
|
20
|
+
const balanceCaipAddress = address || this.getAccounts()?.find(account => account.includes(network.id.toString()));
|
|
21
|
+
const balanceAddress = balanceCaipAddress?.split(':')[2];
|
|
22
|
+
if (!balanceCaipAddress || !balanceAddress) {
|
|
23
|
+
return Promise.resolve({
|
|
24
|
+
amount: '0.00',
|
|
25
|
+
symbol: 'BTC'
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const utxos = await BitcoinAdapter.api.getUTXOs({
|
|
30
|
+
network,
|
|
31
|
+
address: balanceAddress
|
|
32
|
+
});
|
|
33
|
+
const balance = utxos.reduce((acc, utxo) => acc + utxo.value, 0);
|
|
34
|
+
const formattedBalance = UnitsUtil.parseSatoshis(balance.toString(), network);
|
|
35
|
+
this.emit('balanceChanged', {
|
|
36
|
+
namespace: this.getSupportedNamespace(),
|
|
37
|
+
address: balanceCaipAddress,
|
|
38
|
+
balance: {
|
|
39
|
+
amount: formattedBalance,
|
|
40
|
+
symbol: network.nativeCurrency.symbol
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
amount: formattedBalance,
|
|
45
|
+
symbol: network.nativeCurrency.symbol
|
|
46
|
+
};
|
|
47
|
+
} catch (error) {
|
|
48
|
+
return {
|
|
49
|
+
amount: '0.00',
|
|
50
|
+
symbol: 'BTC'
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async switchNetwork(network) {
|
|
55
|
+
if (!this.connector) throw new Error('No active connector');
|
|
56
|
+
const provider = this.connector.getProvider();
|
|
57
|
+
if (!provider) throw new Error('No active provider');
|
|
58
|
+
try {
|
|
59
|
+
await this.connector.switchNetwork(network);
|
|
60
|
+
return;
|
|
61
|
+
} catch (switchError) {
|
|
62
|
+
throw switchError;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
getAccounts() {
|
|
66
|
+
if (!this.connector) throw new Error('No active connector');
|
|
67
|
+
const namespaces = this.connector.getNamespaces();
|
|
68
|
+
return namespaces[this.getSupportedNamespace()]?.accounts;
|
|
69
|
+
}
|
|
70
|
+
disconnect() {
|
|
71
|
+
if (!this.connector) throw new Error('SolanaAdapter:disconnect - No active connector');
|
|
72
|
+
return this.connector.disconnect();
|
|
73
|
+
}
|
|
74
|
+
async request(method, params) {
|
|
75
|
+
if (!this.connector) throw new Error('No active connector');
|
|
76
|
+
const provider = this.connector.getProvider();
|
|
77
|
+
return provider.request({
|
|
78
|
+
method,
|
|
79
|
+
params
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
getSupportedNamespace() {
|
|
83
|
+
return BitcoinAdapter.supportedNamespace;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["BlockchainAdapter","BitcoinApi","UnitsUtil","BitcoinAdapter","supportedNamespace","api","constructor","configParams","projectId","getBalance","params","network","address","connector","Error","balanceCaipAddress","getAccounts","find","account","includes","id","toString","balanceAddress","split","Promise","resolve","amount","symbol","utxos","getUTXOs","balance","reduce","acc","utxo","value","formattedBalance","parseSatoshis","emit","namespace","getSupportedNamespace","nativeCurrency","error","switchNetwork","provider","getProvider","switchError","namespaces","getNamespaces","accounts","disconnect","request","method"],"sourceRoot":"../../src","sources":["adapter.ts"],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["BitcoinAdapter"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,SAASA,cAAc,QAAQ,WAAW;AAC1C,SAASA,cAAc"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const BitcoinApi = {
|
|
2
|
+
getUTXOs: async ({
|
|
3
|
+
network,
|
|
4
|
+
address
|
|
5
|
+
}) => {
|
|
6
|
+
const isTestnet = network.caipNetworkId === 'bip122:000000000933ea01ad0ee984209779ba';
|
|
7
|
+
// Make chain dynamic
|
|
8
|
+
|
|
9
|
+
//TODO: Call rpc to get balance
|
|
10
|
+
const url = `https://mempool.space${isTestnet ? '/testnet' : ''}/api/address/${address}/utxo`;
|
|
11
|
+
const response = await fetch(url);
|
|
12
|
+
if (!response.ok) {
|
|
13
|
+
throw new Error(`Failed to fetch UTXOs: ${await response.text()}`);
|
|
14
|
+
}
|
|
15
|
+
return await response.json();
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=BitcoinApi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["BitcoinApi","getUTXOs","network","address","isTestnet","caipNetworkId","url","response","fetch","ok","Error","text","json"],"sourceRoot":"../../../src","sources":["utils/BitcoinApi.ts"],"mappings":"AAEA,OAAO,MAAMA,UAAgC,GAAG;EAC9CC,QAAQ,EAAE,MAAAA,CAAO;IAAEC,OAAO;IAAEC;EAAmC,CAAC,KAAiC;IAC/F,MAAMC,SAAS,GAAGF,OAAO,CAACG,aAAa,KAAK,yCAAyC;IACrF;;IAEA;IACA,MAAMC,GAAG,GAAI,wBAAuBF,SAAS,GAAG,UAAU,GAAG,EAAG,gBAAeD,OAAQ,OAAM;IAC7F,MAAMI,QAAQ,GAAG,MAAMC,KAAK,CAACF,GAAG,CAAC;IAEjC,IAAI,CAACC,QAAQ,CAACE,EAAE,EAAE;MAChB,MAAM,IAAIC,KAAK,CAAE,0BAAyB,MAAMH,QAAQ,CAACI,IAAI,CAAC,CAAE,EAAC,CAAC;IACpE;IAEA,OAAQ,MAAMJ,QAAQ,CAACK,IAAI,CAAC,CAAC;EAC/B;AACF,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const UnitsUtil = {
|
|
2
|
+
parseSatoshis(amount, network) {
|
|
3
|
+
const value = parseFloat(amount) / 10 ** network.nativeCurrency.decimals;
|
|
4
|
+
return Intl.NumberFormat('en-US', {
|
|
5
|
+
maximumFractionDigits: network.nativeCurrency.decimals
|
|
6
|
+
}).format(value);
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=UnitsUtil.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["UnitsUtil","parseSatoshis","amount","network","value","parseFloat","nativeCurrency","decimals","Intl","NumberFormat","maximumFractionDigits","format"],"sourceRoot":"../../../src","sources":["utils/UnitsUtil.ts"],"mappings":"AAEA,OAAO,MAAMA,SAAS,GAAG;EACvBC,aAAaA,CAACC,MAAc,EAAEC,OAAsB,EAAU;IAC5D,MAAMC,KAAK,GAAGC,UAAU,CAACH,MAAM,CAAC,GAAG,EAAE,IAAIC,OAAO,CAACG,cAAc,CAACC,QAAQ;IAExE,OAAOC,IAAI,CAACC,YAAY,CAAC,OAAO,EAAE;MAChCC,qBAAqB,EAAEP,OAAO,CAACG,cAAc,CAACC;IAChD,CAAC,CAAC,CAACI,MAAM,CAACP,KAAK,CAAC;EAClB;AACF,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BlockchainAdapter, type AppKitNetwork, type CaipAddress, type ChainNamespace, type GetBalanceParams, type GetBalanceResponse } from '@reown/appkit-common-react-native';
|
|
2
|
+
export declare class BitcoinAdapter extends BlockchainAdapter {
|
|
3
|
+
private static supportedNamespace;
|
|
4
|
+
private static api;
|
|
5
|
+
constructor(configParams: {
|
|
6
|
+
projectId: string;
|
|
7
|
+
});
|
|
8
|
+
getBalance(params: GetBalanceParams): Promise<GetBalanceResponse>;
|
|
9
|
+
switchNetwork(network: AppKitNetwork): Promise<void>;
|
|
10
|
+
getAccounts(): CaipAddress[] | undefined;
|
|
11
|
+
disconnect(): Promise<void>;
|
|
12
|
+
request(method: string, params?: any[]): Promise<unknown>;
|
|
13
|
+
getSupportedNamespace(): ChainNamespace;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACxB,MAAM,mCAAmC,CAAC;AAI3C,qBAAa,cAAe,SAAQ,iBAAiB;IACnD,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAA4B;IAC7D,OAAO,CAAC,MAAM,CAAC,GAAG,CAAc;gBAEpB,YAAY,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE;IAOzC,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAuCjE,aAAa,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAe1D,WAAW,IAAI,WAAW,EAAE,GAAG,SAAS;IAOxC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAMrB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE;IAO5C,qBAAqB,IAAI,cAAc;CAGxC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AppKitNetwork } from '@reown/appkit-common-react-native';
|
|
2
|
+
export declare const BitcoinApi: BitcoinApi.Interface;
|
|
3
|
+
export declare namespace BitcoinApi {
|
|
4
|
+
type Interface = {
|
|
5
|
+
getUTXOs: (params: GetUTXOsParams) => Promise<UTXO[]>;
|
|
6
|
+
};
|
|
7
|
+
type GetUTXOsParams = {
|
|
8
|
+
network: AppKitNetwork;
|
|
9
|
+
address: string;
|
|
10
|
+
};
|
|
11
|
+
type UTXO = {
|
|
12
|
+
txid: string;
|
|
13
|
+
vout: number;
|
|
14
|
+
value: number;
|
|
15
|
+
status: {
|
|
16
|
+
confirmed: boolean;
|
|
17
|
+
block_height: number;
|
|
18
|
+
block_hash: string;
|
|
19
|
+
block_time: number;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=BitcoinApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BitcoinApi.d.ts","sourceRoot":"","sources":["../../../src/utils/BitcoinApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAEvE,eAAO,MAAM,UAAU,EAAE,UAAU,CAAC,SAenC,CAAC;AAEF,yBAAiB,UAAU,CAAC;IAC1B,KAAY,SAAS,GAAG;QACtB,QAAQ,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;KACvD,CAAC;IAEF,KAAY,cAAc,GAAG;QAC3B,OAAO,EAAE,aAAa,CAAC;QACvB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IAEF,KAAY,IAAI,GAAG;QACjB,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE;YACN,SAAS,EAAE,OAAO,CAAC;YACnB,YAAY,EAAE,MAAM,CAAC;YACrB,UAAU,EAAE,MAAM,CAAC;YACnB,UAAU,EAAE,MAAM,CAAC;SACpB,CAAC;KACH,CAAC;CACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnitsUtil.d.ts","sourceRoot":"","sources":["../../../src/utils/UnitsUtil.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAEvE,eAAO,MAAM,SAAS;0BACE,MAAM,WAAW,aAAa,GAAG,MAAM;CAO9D,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@reown/appkit-bitcoin-react-native",
|
|
3
|
+
"version": "0.0.0-feat-multichain-20250513175016",
|
|
4
|
+
"main": "lib/commonjs/index.js",
|
|
5
|
+
"types": "lib/typescript/index.d.ts",
|
|
6
|
+
"module": "lib/module/index.js",
|
|
7
|
+
"source": "src/index.tsx",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "bob build",
|
|
10
|
+
"clean": "rm -rf lib",
|
|
11
|
+
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"src",
|
|
15
|
+
"lib",
|
|
16
|
+
"!**/__tests__",
|
|
17
|
+
"!**/__fixtures__",
|
|
18
|
+
"!**/__mocks__"
|
|
19
|
+
],
|
|
20
|
+
"keywords": [
|
|
21
|
+
"web3",
|
|
22
|
+
"crypto",
|
|
23
|
+
"bitcoin",
|
|
24
|
+
"appkit",
|
|
25
|
+
"reown",
|
|
26
|
+
"walletconnect",
|
|
27
|
+
"react-native"
|
|
28
|
+
],
|
|
29
|
+
"repository": "https://github.com/reown-com/appkit-react-native",
|
|
30
|
+
"author": "Reown <support@reown.com> (https://reown.com)",
|
|
31
|
+
"homepage": "https://reown.com/appkit",
|
|
32
|
+
"license": "Apache-2.0",
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/reown-com/appkit-react-native/issues"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"registry": "https://registry.npmjs.org/",
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@reown/appkit-common-react-native": "0.0.0-feat-multichain-20250513175016",
|
|
42
|
+
"@solana/web3.js": "1.98.2",
|
|
43
|
+
"bs58": "6.0.0"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"@solana/web3.js": ">=1.90.0",
|
|
47
|
+
"bs58": ">=6.0.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@solana/web3.js": "1.98.2",
|
|
51
|
+
"bs58": "6.0.0"
|
|
52
|
+
},
|
|
53
|
+
"react-native": "src/index.tsx"
|
|
54
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#### 📚 [Documentation](https://docs.reown.com/appkit/react-native/core/installation)
|
|
2
|
+
|
|
3
|
+
#### 🔎 [Examples](https://github.com/reown-com/react-native-examples)
|
|
4
|
+
|
|
5
|
+
#### 🔗 [Website](https://reown.com/appkit)
|
|
6
|
+
|
|
7
|
+
# AppKit
|
|
8
|
+
|
|
9
|
+
Your on-ramp to web3 multichain. AppKit is a versatile library that makes it super easy to connect users with your Dapp and start interacting with the blockchain.
|
package/src/adapter.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BlockchainAdapter,
|
|
3
|
+
type AppKitNetwork,
|
|
4
|
+
type CaipAddress,
|
|
5
|
+
type ChainNamespace,
|
|
6
|
+
type GetBalanceParams,
|
|
7
|
+
type GetBalanceResponse
|
|
8
|
+
} from '@reown/appkit-common-react-native';
|
|
9
|
+
import { BitcoinApi } from './utils/BitcoinApi';
|
|
10
|
+
import { UnitsUtil } from './utils/UnitsUtil';
|
|
11
|
+
|
|
12
|
+
export class BitcoinAdapter extends BlockchainAdapter {
|
|
13
|
+
private static supportedNamespace: ChainNamespace = 'bip122';
|
|
14
|
+
private static api = BitcoinApi;
|
|
15
|
+
|
|
16
|
+
constructor(configParams: { projectId: string }) {
|
|
17
|
+
super({
|
|
18
|
+
projectId: configParams.projectId,
|
|
19
|
+
supportedNamespace: BitcoinAdapter.supportedNamespace
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async getBalance(params: GetBalanceParams): Promise<GetBalanceResponse> {
|
|
24
|
+
const { network, address } = params;
|
|
25
|
+
|
|
26
|
+
if (!this.connector) throw new Error('No active connector');
|
|
27
|
+
if (!network) throw new Error('No network provided');
|
|
28
|
+
|
|
29
|
+
const balanceCaipAddress =
|
|
30
|
+
address || this.getAccounts()?.find(account => account.includes(network.id.toString()));
|
|
31
|
+
|
|
32
|
+
const balanceAddress = balanceCaipAddress?.split(':')[2];
|
|
33
|
+
|
|
34
|
+
if (!balanceCaipAddress || !balanceAddress) {
|
|
35
|
+
return Promise.resolve({ amount: '0.00', symbol: 'BTC' });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
const utxos = await BitcoinAdapter.api.getUTXOs({
|
|
40
|
+
network,
|
|
41
|
+
address: balanceAddress
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const balance = utxos.reduce((acc, utxo) => acc + utxo.value, 0);
|
|
45
|
+
const formattedBalance = UnitsUtil.parseSatoshis(balance.toString(), network);
|
|
46
|
+
|
|
47
|
+
this.emit('balanceChanged', {
|
|
48
|
+
namespace: this.getSupportedNamespace(),
|
|
49
|
+
address: balanceCaipAddress,
|
|
50
|
+
balance: {
|
|
51
|
+
amount: formattedBalance,
|
|
52
|
+
symbol: network.nativeCurrency.symbol
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return { amount: formattedBalance, symbol: network.nativeCurrency.symbol };
|
|
57
|
+
} catch (error) {
|
|
58
|
+
return { amount: '0.00', symbol: 'BTC' };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async switchNetwork(network: AppKitNetwork): Promise<void> {
|
|
63
|
+
if (!this.connector) throw new Error('No active connector');
|
|
64
|
+
|
|
65
|
+
const provider = this.connector.getProvider();
|
|
66
|
+
if (!provider) throw new Error('No active provider');
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
await this.connector.switchNetwork(network);
|
|
70
|
+
|
|
71
|
+
return;
|
|
72
|
+
} catch (switchError: any) {
|
|
73
|
+
throw switchError;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
getAccounts(): CaipAddress[] | undefined {
|
|
78
|
+
if (!this.connector) throw new Error('No active connector');
|
|
79
|
+
const namespaces = this.connector.getNamespaces();
|
|
80
|
+
|
|
81
|
+
return namespaces[this.getSupportedNamespace()]?.accounts;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
disconnect(): Promise<void> {
|
|
85
|
+
if (!this.connector) throw new Error('SolanaAdapter:disconnect - No active connector');
|
|
86
|
+
|
|
87
|
+
return this.connector.disconnect();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async request(method: string, params?: any[]) {
|
|
91
|
+
if (!this.connector) throw new Error('No active connector');
|
|
92
|
+
const provider = this.connector.getProvider();
|
|
93
|
+
|
|
94
|
+
return provider.request({ method, params });
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
getSupportedNamespace(): ChainNamespace {
|
|
98
|
+
return BitcoinAdapter.supportedNamespace;
|
|
99
|
+
}
|
|
100
|
+
}
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { AppKitNetwork } from '@reown/appkit-common-react-native';
|
|
2
|
+
|
|
3
|
+
export const BitcoinApi: BitcoinApi.Interface = {
|
|
4
|
+
getUTXOs: async ({ network, address }: BitcoinApi.GetUTXOsParams): Promise<BitcoinApi.UTXO[]> => {
|
|
5
|
+
const isTestnet = network.caipNetworkId === 'bip122:000000000933ea01ad0ee984209779ba';
|
|
6
|
+
// Make chain dynamic
|
|
7
|
+
|
|
8
|
+
//TODO: Call rpc to get balance
|
|
9
|
+
const url = `https://mempool.space${isTestnet ? '/testnet' : ''}/api/address/${address}/utxo`;
|
|
10
|
+
const response = await fetch(url);
|
|
11
|
+
|
|
12
|
+
if (!response.ok) {
|
|
13
|
+
throw new Error(`Failed to fetch UTXOs: ${await response.text()}`);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return (await response.json()) as BitcoinApi.UTXO[];
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export namespace BitcoinApi {
|
|
21
|
+
export type Interface = {
|
|
22
|
+
getUTXOs: (params: GetUTXOsParams) => Promise<UTXO[]>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type GetUTXOsParams = {
|
|
26
|
+
network: AppKitNetwork;
|
|
27
|
+
address: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type UTXO = {
|
|
31
|
+
txid: string;
|
|
32
|
+
vout: number;
|
|
33
|
+
value: number;
|
|
34
|
+
status: {
|
|
35
|
+
confirmed: boolean;
|
|
36
|
+
block_height: number;
|
|
37
|
+
block_hash: string;
|
|
38
|
+
block_time: number;
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AppKitNetwork } from '@reown/appkit-common-react-native';
|
|
2
|
+
|
|
3
|
+
export const UnitsUtil = {
|
|
4
|
+
parseSatoshis(amount: string, network: AppKitNetwork): string {
|
|
5
|
+
const value = parseFloat(amount) / 10 ** network.nativeCurrency.decimals;
|
|
6
|
+
|
|
7
|
+
return Intl.NumberFormat('en-US', {
|
|
8
|
+
maximumFractionDigits: network.nativeCurrency.decimals
|
|
9
|
+
}).format(value);
|
|
10
|
+
}
|
|
11
|
+
};
|