@reown/appkit-core-react-native 0.0.0-feat-wallet-features-20240925132010 → 0.0.0-fix-email-login-20241010173711
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/controllers/AccountController.js +1 -25
- package/lib/commonjs/controllers/AccountController.js.map +1 -1
- package/lib/commonjs/controllers/ApiController.js +3 -3
- package/lib/commonjs/controllers/ApiController.js.map +1 -1
- package/lib/commonjs/controllers/BlockchainApiController.js +0 -84
- package/lib/commonjs/controllers/BlockchainApiController.js.map +1 -1
- package/lib/commonjs/controllers/ConnectionController.js +0 -19
- package/lib/commonjs/controllers/ConnectionController.js.map +1 -1
- package/lib/commonjs/controllers/EventsController.js +15 -1
- package/lib/commonjs/controllers/EventsController.js.map +1 -1
- package/lib/commonjs/controllers/ModalController.js +1 -1
- package/lib/commonjs/controllers/ModalController.js.map +1 -1
- package/lib/commonjs/controllers/NetworkController.js +0 -3
- package/lib/commonjs/controllers/NetworkController.js.map +1 -1
- package/lib/commonjs/controllers/OptionsController.js +1 -1
- package/lib/commonjs/controllers/OptionsController.js.map +1 -1
- package/lib/commonjs/controllers/RouterController.js +1 -22
- package/lib/commonjs/controllers/RouterController.js.map +1 -1
- package/lib/commonjs/index.js +0 -35
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/ConstantsUtil.js +1 -2
- package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
- package/lib/commonjs/utils/CoreHelperUtil.js +0 -33
- package/lib/commonjs/utils/CoreHelperUtil.js.map +1 -1
- package/lib/commonjs/utils/FetchUtil.js.map +1 -1
- package/lib/commonjs/utils/TypeUtil.js +0 -4
- package/lib/module/controllers/AccountController.js +1 -25
- package/lib/module/controllers/AccountController.js.map +1 -1
- package/lib/module/controllers/ApiController.js +3 -3
- package/lib/module/controllers/ApiController.js.map +1 -1
- package/lib/module/controllers/BlockchainApiController.js +0 -84
- package/lib/module/controllers/BlockchainApiController.js.map +1 -1
- package/lib/module/controllers/ConnectionController.js +0 -19
- package/lib/module/controllers/ConnectionController.js.map +1 -1
- package/lib/module/controllers/EventsController.js +15 -1
- package/lib/module/controllers/EventsController.js.map +1 -1
- package/lib/module/controllers/ModalController.js +1 -1
- package/lib/module/controllers/ModalController.js.map +1 -1
- package/lib/module/controllers/NetworkController.js +0 -3
- package/lib/module/controllers/NetworkController.js.map +1 -1
- package/lib/module/controllers/OptionsController.js +1 -1
- package/lib/module/controllers/OptionsController.js.map +1 -1
- package/lib/module/controllers/RouterController.js +1 -22
- package/lib/module/controllers/RouterController.js.map +1 -1
- package/lib/module/index.js +0 -6
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/ConstantsUtil.js +1 -2
- package/lib/module/utils/ConstantsUtil.js.map +1 -1
- package/lib/module/utils/CoreHelperUtil.js +0 -33
- package/lib/module/utils/CoreHelperUtil.js.map +1 -1
- package/lib/module/utils/FetchUtil.js.map +1 -1
- package/lib/module/utils/TypeUtil.js +1 -1
- package/lib/typescript/controllers/AccountController.d.ts +0 -4
- package/lib/typescript/controllers/AccountController.d.ts.map +1 -1
- package/lib/typescript/controllers/ApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/BlockchainApiController.d.ts +1 -6
- package/lib/typescript/controllers/BlockchainApiController.d.ts.map +1 -1
- package/lib/typescript/controllers/ConnectionController.d.ts +1 -13
- package/lib/typescript/controllers/ConnectionController.d.ts.map +1 -1
- package/lib/typescript/controllers/EventsController.d.ts +6 -0
- package/lib/typescript/controllers/EventsController.d.ts.map +1 -1
- package/lib/typescript/controllers/NetworkController.d.ts +0 -1
- package/lib/typescript/controllers/NetworkController.d.ts.map +1 -1
- package/lib/typescript/controllers/RouterController.d.ts +1 -13
- package/lib/typescript/controllers/RouterController.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +26 -18
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/utils/ConstantsUtil.d.ts +0 -1
- package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
- package/lib/typescript/utils/CoreHelperUtil.d.ts +0 -6
- package/lib/typescript/utils/CoreHelperUtil.d.ts.map +1 -1
- package/lib/typescript/utils/FetchUtil.d.ts +0 -3
- package/lib/typescript/utils/FetchUtil.d.ts.map +1 -1
- package/lib/typescript/utils/TypeUtil.d.ts +0 -137
- package/lib/typescript/utils/TypeUtil.d.ts.map +1 -1
- package/package.json +5 -5
- package/readme.md +1 -1
- package/src/controllers/AccountController.ts +1 -35
- package/src/controllers/ApiController.ts +7 -3
- package/src/controllers/BlockchainApiController.ts +1 -88
- package/src/controllers/ConnectionController.ts +1 -37
- package/src/controllers/EventsController.ts +13 -1
- package/src/controllers/ModalController.ts +1 -1
- package/src/controllers/NetworkController.ts +0 -6
- package/src/controllers/OptionsController.ts +1 -1
- package/src/controllers/RouterController.ts +10 -52
- package/src/index.ts +30 -41
- package/src/utils/ConstantsUtil.ts +1 -3
- package/src/utils/CoreHelperUtil.ts +1 -38
- package/src/utils/FetchUtil.ts +0 -4
- package/src/utils/TypeUtil.ts +0 -169
- package/lib/commonjs/controllers/EnsController.js +0 -35
- package/lib/commonjs/controllers/EnsController.js.map +0 -1
- package/lib/commonjs/controllers/SendController.js +0 -176
- package/lib/commonjs/controllers/SendController.js.map +0 -1
- package/lib/commonjs/controllers/SwapController.js +0 -91
- package/lib/commonjs/controllers/SwapController.js.map +0 -1
- package/lib/commonjs/controllers/TransactionsController.js +0 -112
- package/lib/commonjs/controllers/TransactionsController.js.map +0 -1
- package/lib/commonjs/utils/ApiUtil.js +0 -18
- package/lib/commonjs/utils/ApiUtil.js.map +0 -1
- package/lib/commonjs/utils/SwapApiUtil.js +0 -23
- package/lib/commonjs/utils/SwapApiUtil.js.map +0 -1
- package/lib/commonjs/utils/SwapCalculationUtil.js +0 -24
- package/lib/commonjs/utils/SwapCalculationUtil.js.map +0 -1
- package/lib/module/controllers/EnsController.js +0 -30
- package/lib/module/controllers/EnsController.js.map +0 -1
- package/lib/module/controllers/SendController.js +0 -171
- package/lib/module/controllers/SendController.js.map +0 -1
- package/lib/module/controllers/SwapController.js +0 -86
- package/lib/module/controllers/SwapController.js.map +0 -1
- package/lib/module/controllers/TransactionsController.js +0 -107
- package/lib/module/controllers/TransactionsController.js.map +0 -1
- package/lib/module/utils/ApiUtil.js +0 -12
- package/lib/module/utils/ApiUtil.js.map +0 -1
- package/lib/module/utils/SwapApiUtil.js +0 -17
- package/lib/module/utils/SwapApiUtil.js.map +0 -1
- package/lib/module/utils/SwapCalculationUtil.js +0 -19
- package/lib/module/utils/SwapCalculationUtil.js.map +0 -1
- package/lib/typescript/controllers/EnsController.d.ts +0 -10
- package/lib/typescript/controllers/EnsController.d.ts.map +0 -1
- package/lib/typescript/controllers/SendController.d.ts +0 -41
- package/lib/typescript/controllers/SendController.d.ts.map +0 -1
- package/lib/typescript/controllers/SwapController.d.ts +0 -29
- package/lib/typescript/controllers/SwapController.d.ts.map +0 -1
- package/lib/typescript/controllers/TransactionsController.d.ts +0 -21
- package/lib/typescript/controllers/TransactionsController.d.ts.map +0 -1
- package/lib/typescript/utils/ApiUtil.d.ts +0 -5
- package/lib/typescript/utils/ApiUtil.d.ts.map +0 -1
- package/lib/typescript/utils/SwapApiUtil.d.ts +0 -4
- package/lib/typescript/utils/SwapApiUtil.d.ts.map +0 -1
- package/lib/typescript/utils/SwapCalculationUtil.d.ts +0 -5
- package/lib/typescript/utils/SwapCalculationUtil.d.ts.map +0 -1
- package/src/controllers/EnsController.ts +0 -39
- package/src/controllers/SendController.ts +0 -234
- package/src/controllers/SwapController.ts +0 -108
- package/src/controllers/TransactionsController.ts +0 -142
- package/src/utils/ApiUtil.ts +0 -18
- package/src/utils/SwapApiUtil.ts +0 -19
- package/src/utils/SwapCalculationUtil.ts +0 -21
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { proxy, subscribe as sub } from 'valtio/vanilla';
|
|
2
|
-
import { OptionsController } from './OptionsController';
|
|
3
|
-
import { EventsController } from './EventsController';
|
|
4
|
-
import { SnackController } from './SnackController';
|
|
5
|
-
import { NetworkController } from './NetworkController';
|
|
6
|
-
import { BlockchainApiController } from './BlockchainApiController';
|
|
7
|
-
|
|
8
|
-
// -- Types --------------------------------------------- //
|
|
9
|
-
|
|
10
|
-
// -- State --------------------------------------------- //
|
|
11
|
-
const state = proxy({
|
|
12
|
-
transactions: [],
|
|
13
|
-
loading: false,
|
|
14
|
-
empty: false,
|
|
15
|
-
next: undefined
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
// -- Controller ---------------------------------------- //
|
|
19
|
-
export const TransactionsController = {
|
|
20
|
-
state,
|
|
21
|
-
subscribe(callback) {
|
|
22
|
-
return sub(state, () => callback(state));
|
|
23
|
-
},
|
|
24
|
-
async fetchTransactions(accountAddress, reset) {
|
|
25
|
-
const {
|
|
26
|
-
projectId
|
|
27
|
-
} = OptionsController.state;
|
|
28
|
-
if (!projectId || !accountAddress) {
|
|
29
|
-
throw new Error("Transactions can't be fetched without a projectId and an accountAddress");
|
|
30
|
-
}
|
|
31
|
-
state.loading = true;
|
|
32
|
-
if (reset) {
|
|
33
|
-
state.next = undefined;
|
|
34
|
-
}
|
|
35
|
-
try {
|
|
36
|
-
const response = await BlockchainApiController.fetchTransactions({
|
|
37
|
-
account: accountAddress,
|
|
38
|
-
projectId,
|
|
39
|
-
cursor: state.next
|
|
40
|
-
});
|
|
41
|
-
const nonSpamTransactions = this.filterSpamTransactions(response?.data ?? []);
|
|
42
|
-
let filteredTransactions = [...state.transactions, ...nonSpamTransactions];
|
|
43
|
-
filteredTransactions = [...state.transactions, ...nonSpamTransactions];
|
|
44
|
-
if (reset) {
|
|
45
|
-
filteredTransactions = nonSpamTransactions;
|
|
46
|
-
}
|
|
47
|
-
state.loading = false;
|
|
48
|
-
state.transactions = filteredTransactions;
|
|
49
|
-
state.empty = nonSpamTransactions.length === 0;
|
|
50
|
-
state.next = response?.next ? response.next : undefined;
|
|
51
|
-
} catch (error) {
|
|
52
|
-
EventsController.sendEvent({
|
|
53
|
-
type: 'track',
|
|
54
|
-
event: 'ERROR_FETCH_TRANSACTIONS',
|
|
55
|
-
properties: {
|
|
56
|
-
address: accountAddress,
|
|
57
|
-
projectId,
|
|
58
|
-
cursor: state.next,
|
|
59
|
-
isSmartAccount: false
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
SnackController.showError('Failed to fetch transactions');
|
|
63
|
-
state.loading = false;
|
|
64
|
-
state.empty = true;
|
|
65
|
-
state.next = undefined;
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
getTransactionsByYearAndMonth(transactions) {
|
|
69
|
-
const grouped = {};
|
|
70
|
-
let filteredTransactions = this.filterByConnectedChain(transactions);
|
|
71
|
-
filteredTransactions.forEach(transaction => {
|
|
72
|
-
const year = new Date(transaction.metadata.minedAt).getFullYear();
|
|
73
|
-
const month = new Date(transaction.metadata.minedAt).getMonth();
|
|
74
|
-
const yearTransactions = grouped[year] ?? {};
|
|
75
|
-
const monthTransactions = yearTransactions[month] ?? [];
|
|
76
|
-
|
|
77
|
-
// If there's a transaction with the same id, remove the old one
|
|
78
|
-
const newMonthTransactions = monthTransactions.filter(tx => tx.id !== transaction.id);
|
|
79
|
-
grouped[year] = {
|
|
80
|
-
...yearTransactions,
|
|
81
|
-
[month]: [...newMonthTransactions, transaction].sort((a, b) => new Date(b.metadata.minedAt).getTime() - new Date(a.metadata.minedAt).getTime())
|
|
82
|
-
};
|
|
83
|
-
});
|
|
84
|
-
return grouped;
|
|
85
|
-
},
|
|
86
|
-
filterSpamTransactions(transactions) {
|
|
87
|
-
return transactions.filter(transaction => {
|
|
88
|
-
const isAllSpam = transaction.transfers.every(transfer => transfer.nft_info?.flags.is_spam === true);
|
|
89
|
-
return !isAllSpam;
|
|
90
|
-
});
|
|
91
|
-
},
|
|
92
|
-
filterByConnectedChain(transactions) {
|
|
93
|
-
const chainId = NetworkController.state.caipNetwork?.id;
|
|
94
|
-
const filteredTransactions = transactions.filter(transaction => transaction.metadata.chain === chainId);
|
|
95
|
-
return filteredTransactions;
|
|
96
|
-
},
|
|
97
|
-
clearCursor() {
|
|
98
|
-
state.next = undefined;
|
|
99
|
-
},
|
|
100
|
-
resetTransactions() {
|
|
101
|
-
state.transactions = [];
|
|
102
|
-
state.loading = false;
|
|
103
|
-
state.empty = false;
|
|
104
|
-
state.next = undefined;
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
//# sourceMappingURL=TransactionsController.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["proxy","subscribe","sub","OptionsController","EventsController","SnackController","NetworkController","BlockchainApiController","state","transactions","loading","empty","next","undefined","TransactionsController","callback","fetchTransactions","accountAddress","reset","projectId","Error","response","account","cursor","nonSpamTransactions","filterSpamTransactions","data","filteredTransactions","length","error","sendEvent","type","event","properties","address","isSmartAccount","showError","getTransactionsByYearAndMonth","grouped","filterByConnectedChain","forEach","transaction","year","Date","metadata","minedAt","getFullYear","month","getMonth","yearTransactions","monthTransactions","newMonthTransactions","filter","tx","id","sort","a","b","getTime","isAllSpam","transfers","every","transfer","nft_info","flags","is_spam","chainId","caipNetwork","chain","clearCursor","resetTransactions"],"sourceRoot":"../../../src","sources":["controllers/TransactionsController.ts"],"mappings":"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"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Platform } from 'react-native';
|
|
2
|
-
import { CoreHelperUtil } from './CoreHelperUtil';
|
|
3
|
-
export const ApiUtil = {
|
|
4
|
-
getOrigin() {
|
|
5
|
-
return CoreHelperUtil.getBundleId();
|
|
6
|
-
},
|
|
7
|
-
getUserAgent() {
|
|
8
|
-
const reactNativeVersion = [Platform.constants.reactNativeVersion.major, Platform.constants.reactNativeVersion.minor, Platform.constants.reactNativeVersion.patch].join('.');
|
|
9
|
-
return `${Platform.OS}-${Platform.Version}@rn-${reactNativeVersion}`;
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=ApiUtil.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["Platform","CoreHelperUtil","ApiUtil","getOrigin","getBundleId","getUserAgent","reactNativeVersion","constants","major","minor","patch","join","OS","Version"],"sourceRoot":"../../../src","sources":["utils/ApiUtil.ts"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,cAAc;AACvC,SAASC,cAAc,QAAQ,kBAAkB;AAEjD,OAAO,MAAMC,OAAO,GAAG;EACrBC,SAASA,CAAA,EAAG;IACV,OAAOF,cAAc,CAACG,WAAW,CAAC,CAAC;EACrC,CAAC;EAEDC,YAAYA,CAAA,EAAG;IACb,MAAMC,kBAAkB,GAAG,CACzBN,QAAQ,CAACO,SAAS,CAACD,kBAAkB,CAACE,KAAK,EAC3CR,QAAQ,CAACO,SAAS,CAACD,kBAAkB,CAACG,KAAK,EAC3CT,QAAQ,CAACO,SAAS,CAACD,kBAAkB,CAACI,KAAK,CAC5C,CAACC,IAAI,CAAC,GAAG,CAAC;IAEX,OAAQ,GAAEX,QAAQ,CAACY,EAAG,IAAGZ,QAAQ,CAACa,OAAQ,OAAMP,kBAAmB,EAAC;EACtE;AACF,CAAC"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { BlockchainApiController } from '../controllers/BlockchainApiController';
|
|
2
|
-
import { OptionsController } from '../controllers/OptionsController';
|
|
3
|
-
import { NetworkController } from '../controllers/NetworkController';
|
|
4
|
-
export const SwapApiUtil = {
|
|
5
|
-
async fetchGasPrice() {
|
|
6
|
-
const projectId = OptionsController.state.projectId;
|
|
7
|
-
const caipNetwork = NetworkController.state.caipNetwork;
|
|
8
|
-
if (!caipNetwork) {
|
|
9
|
-
return null;
|
|
10
|
-
}
|
|
11
|
-
return await BlockchainApiController.fetchGasPrice({
|
|
12
|
-
projectId,
|
|
13
|
-
chainId: caipNetwork.id
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=SwapApiUtil.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["BlockchainApiController","OptionsController","NetworkController","SwapApiUtil","fetchGasPrice","projectId","state","caipNetwork","chainId","id"],"sourceRoot":"../../../src","sources":["utils/SwapApiUtil.ts"],"mappings":"AAAA,SAASA,uBAAuB,QAAQ,wCAAwC;AAChF,SAASC,iBAAiB,QAAQ,kCAAkC;AACpE,SAASC,iBAAiB,QAAQ,kCAAkC;AAEpE,OAAO,MAAMC,WAAW,GAAG;EACzB,MAAMC,aAAaA,CAAA,EAAG;IACpB,MAAMC,SAAS,GAAGJ,iBAAiB,CAACK,KAAK,CAACD,SAAS;IACnD,MAAME,WAAW,GAAGL,iBAAiB,CAACI,KAAK,CAACC,WAAW;IAEvD,IAAI,CAACA,WAAW,EAAE;MAChB,OAAO,IAAI;IACb;IAEA,OAAO,MAAMP,uBAAuB,CAACI,aAAa,CAAC;MACjDC,SAAS;MACTG,OAAO,EAAED,WAAW,CAACE;IACvB,CAAC,CAAC;EACJ;AACF,CAAC"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// -- Types --------------------------------------------- //
|
|
2
|
-
|
|
3
|
-
import { NumberUtil } from '@reown/appkit-common-react-native';
|
|
4
|
-
|
|
5
|
-
// -- Util ---------------------------------------- //
|
|
6
|
-
export const SwapCalculationUtil = {
|
|
7
|
-
getGasPriceInEther(gas, gasPrice) {
|
|
8
|
-
const totalGasCostInWei = gasPrice * gas;
|
|
9
|
-
const totalGasCostInEther = Number(totalGasCostInWei) / 1e18;
|
|
10
|
-
return totalGasCostInEther;
|
|
11
|
-
},
|
|
12
|
-
getGasPriceInUSD(networkPrice, gas, gasPrice) {
|
|
13
|
-
const totalGasCostInEther = SwapCalculationUtil.getGasPriceInEther(gas, gasPrice);
|
|
14
|
-
const networkPriceInUSD = NumberUtil.bigNumber(networkPrice);
|
|
15
|
-
const gasCostInUSD = networkPriceInUSD.multipliedBy(totalGasCostInEther);
|
|
16
|
-
return gasCostInUSD.toNumber();
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
//# sourceMappingURL=SwapCalculationUtil.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["NumberUtil","SwapCalculationUtil","getGasPriceInEther","gas","gasPrice","totalGasCostInWei","totalGasCostInEther","Number","getGasPriceInUSD","networkPrice","networkPriceInUSD","bigNumber","gasCostInUSD","multipliedBy","toNumber"],"sourceRoot":"../../../src","sources":["utils/SwapCalculationUtil.ts"],"mappings":"AAAA;;AAEA,SAASA,UAAU,QAAQ,mCAAmC;;AAE9D;AACA,OAAO,MAAMC,mBAAmB,GAAG;EACjCC,kBAAkBA,CAACC,GAAW,EAAEC,QAAgB,EAAE;IAChD,MAAMC,iBAAiB,GAAGD,QAAQ,GAAGD,GAAG;IACxC,MAAMG,mBAAmB,GAAGC,MAAM,CAACF,iBAAiB,CAAC,GAAG,IAAI;IAE5D,OAAOC,mBAAmB;EAC5B,CAAC;EAEDE,gBAAgBA,CAACC,YAAoB,EAAEN,GAAW,EAAEC,QAAgB,EAAE;IACpE,MAAME,mBAAmB,GAAGL,mBAAmB,CAACC,kBAAkB,CAACC,GAAG,EAAEC,QAAQ,CAAC;IACjF,MAAMM,iBAAiB,GAAGV,UAAU,CAACW,SAAS,CAACF,YAAY,CAAC;IAC5D,MAAMG,YAAY,GAAGF,iBAAiB,CAACG,YAAY,CAACP,mBAAmB,CAAC;IAExE,OAAOM,YAAY,CAACE,QAAQ,CAAC,CAAC;EAChC;AACF,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export interface EnsControllerState {
|
|
2
|
-
loading: boolean;
|
|
3
|
-
}
|
|
4
|
-
export declare const EnsController: {
|
|
5
|
-
state: EnsControllerState;
|
|
6
|
-
subscribe(callback: (newState: EnsControllerState) => void): () => void;
|
|
7
|
-
subscribeKey<K extends "loading">(key: K, callback: (value: EnsControllerState[K]) => void): () => void;
|
|
8
|
-
resolveName(name: string): Promise<import("../utils/TypeUtil").BlockchainApiLookupEnsName | undefined>;
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=EnsController.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EnsController.d.ts","sourceRoot":"","sources":["../../../src/controllers/EnsController.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;CAClB;AAUD,eAAO,MAAM,aAAa;;mCAGO,kBAAkB,KAAK,IAAI;0FAI2B,IAAI;sBAIjE,MAAM;CAQ/B,CAAC"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { type Balance } from '@reown/appkit-common-react-native';
|
|
2
|
-
export interface TxParams {
|
|
3
|
-
receiverAddress: string;
|
|
4
|
-
sendTokenAmount: number;
|
|
5
|
-
gasPrice: bigint;
|
|
6
|
-
decimals: string;
|
|
7
|
-
}
|
|
8
|
-
export interface ContractWriteParams {
|
|
9
|
-
receiverAddress: string;
|
|
10
|
-
tokenAddress: string;
|
|
11
|
-
sendTokenAmount: number;
|
|
12
|
-
decimals: string;
|
|
13
|
-
}
|
|
14
|
-
export interface SendControllerState {
|
|
15
|
-
token?: Balance;
|
|
16
|
-
sendTokenAmount?: number;
|
|
17
|
-
receiverAddress?: string;
|
|
18
|
-
receiverProfileName?: string;
|
|
19
|
-
receiverProfileImageUrl?: string;
|
|
20
|
-
gasPrice?: bigint;
|
|
21
|
-
gasPriceInUSD?: number;
|
|
22
|
-
loading: boolean;
|
|
23
|
-
}
|
|
24
|
-
export declare const SendController: {
|
|
25
|
-
state: SendControllerState;
|
|
26
|
-
subscribe(callback: (newState: SendControllerState) => void): () => void;
|
|
27
|
-
subscribeKey<K extends keyof SendControllerState>(key: K, callback: (value: SendControllerState[K]) => void): () => void;
|
|
28
|
-
setToken(token: SendControllerState['token']): void;
|
|
29
|
-
setTokenAmount(sendTokenAmount: SendControllerState['sendTokenAmount']): void;
|
|
30
|
-
setReceiverAddress(receiverAddress: SendControllerState['receiverAddress']): void;
|
|
31
|
-
setReceiverProfileImageUrl(receiverProfileImageUrl: SendControllerState['receiverProfileImageUrl']): void;
|
|
32
|
-
setReceiverProfileName(receiverProfileName: SendControllerState['receiverProfileName']): void;
|
|
33
|
-
setGasPrice(gasPrice: SendControllerState['gasPrice']): void;
|
|
34
|
-
setGasPriceInUsd(gasPriceInUSD: SendControllerState['gasPriceInUSD']): void;
|
|
35
|
-
setLoading(loading: SendControllerState['loading']): void;
|
|
36
|
-
sendToken(): void;
|
|
37
|
-
sendNativeToken(params: TxParams): Promise<void>;
|
|
38
|
-
sendERC20Token(params: ContractWriteParams): Promise<void>;
|
|
39
|
-
resetSend(): void;
|
|
40
|
-
};
|
|
41
|
-
//# sourceMappingURL=SendController.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SendController.d.ts","sourceRoot":"","sources":["../../../src/controllers/SendController.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgB,KAAK,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAU/E,MAAM,WAAW,QAAQ;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,mBAAmB;IAClC,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;CAClB;AAUD,eAAO,MAAM,cAAc;;mCAGM,mBAAmB,KAAK,IAAI;2GAI2B,IAAI;oBAI1E,mBAAmB,CAAC,OAAO,CAAC;oCAMZ,mBAAmB,CAAC,iBAAiB,CAAC;wCAIlC,mBAAmB,CAAC,iBAAiB,CAAC;wDAK/C,mBAAmB,CAAC,yBAAyB,CAAC;gDAK7B,mBAAmB,CAAC,qBAAqB,CAAC;0BAIhE,mBAAmB,CAAC,UAAU,CAAC;oCAIrB,mBAAmB,CAAC,eAAe,CAAC;wBAIhD,mBAAmB,CAAC,SAAS,CAAC;;4BAiDpB,QAAQ;2BAkDT,mBAAmB;;CA8CjD,CAAC"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
export declare const INITIAL_GAS_LIMIT = 150000;
|
|
2
|
-
export declare const TO_AMOUNT_DECIMALS = 6;
|
|
3
|
-
export interface SwapControllerState {
|
|
4
|
-
networkPrice: string;
|
|
5
|
-
networkTokenSymbol: string;
|
|
6
|
-
tokensPriceMap: Record<string, number>;
|
|
7
|
-
gasFee: string;
|
|
8
|
-
gasPriceInUSD?: number;
|
|
9
|
-
}
|
|
10
|
-
export declare const SwapController: {
|
|
11
|
-
state: SwapControllerState;
|
|
12
|
-
subscribe(callback: (newState: SwapControllerState) => void): () => void;
|
|
13
|
-
subscribeKey<K extends keyof SwapControllerState>(key: K, callback: (value: SwapControllerState[K]) => void): () => void;
|
|
14
|
-
getParams(): {
|
|
15
|
-
networkAddress: string;
|
|
16
|
-
};
|
|
17
|
-
resetState(): void;
|
|
18
|
-
getNetworkTokenPrice(): Promise<void>;
|
|
19
|
-
getInitialGasPrice(): Promise<{
|
|
20
|
-
gasPrice: null;
|
|
21
|
-
gasPriceInUsd: null;
|
|
22
|
-
gasPriceInUSD?: undefined;
|
|
23
|
-
} | {
|
|
24
|
-
gasPrice: bigint;
|
|
25
|
-
gasPriceInUSD: number;
|
|
26
|
-
gasPriceInUsd?: undefined;
|
|
27
|
-
}>;
|
|
28
|
-
};
|
|
29
|
-
//# sourceMappingURL=SwapController.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SwapController.d.ts","sourceRoot":"","sources":["../../../src/controllers/SwapController.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,iBAAiB,SAAS,CAAC;AACxC,eAAO,MAAM,kBAAkB,IAAI,CAAC;AAIpC,MAAM,WAAW,mBAAmB;IAElC,YAAY,EAAE,MAAM,CAAC;IACrB,kBAAkB,EAAE,MAAM,CAAC;IAG3B,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAGvC,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAqBD,eAAO,MAAM,cAAc;;mCAGM,mBAAmB,KAAK,IAAI;2GAI2B,IAAI;;;;;;;;;;;;;;;CAoD3F,CAAC"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { Transaction } from '@reown/appkit-common-react-native';
|
|
2
|
-
type TransactionByMonthMap = Record<string, Transaction[]>;
|
|
3
|
-
type TransactionByYearMap = Record<string, TransactionByMonthMap>;
|
|
4
|
-
export interface TransactionsControllerState {
|
|
5
|
-
transactions: Transaction[];
|
|
6
|
-
loading: boolean;
|
|
7
|
-
empty: boolean;
|
|
8
|
-
next: string | undefined;
|
|
9
|
-
}
|
|
10
|
-
export declare const TransactionsController: {
|
|
11
|
-
state: TransactionsControllerState;
|
|
12
|
-
subscribe(callback: (newState: TransactionsControllerState) => void): () => void;
|
|
13
|
-
fetchTransactions(accountAddress?: string, reset?: boolean): Promise<void>;
|
|
14
|
-
getTransactionsByYearAndMonth(transactions: Transaction[]): TransactionByYearMap;
|
|
15
|
-
filterSpamTransactions(transactions: Transaction[]): Transaction[];
|
|
16
|
-
filterByConnectedChain(transactions: Transaction[]): Transaction[];
|
|
17
|
-
clearCursor(): void;
|
|
18
|
-
resetTransactions(): void;
|
|
19
|
-
};
|
|
20
|
-
export {};
|
|
21
|
-
//# sourceMappingURL=TransactionsController.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionsController.d.ts","sourceRoot":"","sources":["../../../src/controllers/TransactionsController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AASrE,KAAK,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;AAC3D,KAAK,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;AAElE,MAAM,WAAW,2BAA2B;IAC1C,YAAY,EAAE,WAAW,EAAE,CAAC;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B;AAWD,eAAO,MAAM,sBAAsB;;mCAGF,2BAA2B,KAAK,IAAI;uCAI1B,MAAM,UAAU,OAAO;gDAoDpB,WAAW,EAAE;yCAyBpB,WAAW,EAAE;yCAUb,WAAW,EAAE;;;CAmBnD,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ApiUtil.d.ts","sourceRoot":"","sources":["../../../src/utils/ApiUtil.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO;;;CAcnB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SwapApiUtil.d.ts","sourceRoot":"","sources":["../../../src/utils/SwapApiUtil.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,WAAW;;CAcvB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SwapCalculationUtil.d.ts","sourceRoot":"","sources":["../../../src/utils/SwapCalculationUtil.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,mBAAmB;4BACN,MAAM,YAAY,MAAM;mCAOjB,MAAM,OAAO,MAAM,YAAY,MAAM;CAOrE,CAAC"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { subscribeKey as subKey } from 'valtio/vanilla/utils';
|
|
2
|
-
import { proxy, subscribe as sub } from 'valtio/vanilla';
|
|
3
|
-
import { BlockchainApiController } from './BlockchainApiController';
|
|
4
|
-
import type { BlockchainApiEnsError } from '../utils/TypeUtil';
|
|
5
|
-
|
|
6
|
-
// -- Types --------------------------------------------- //
|
|
7
|
-
|
|
8
|
-
export interface EnsControllerState {
|
|
9
|
-
loading: boolean;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
type StateKey = keyof EnsControllerState;
|
|
13
|
-
|
|
14
|
-
// -- State --------------------------------------------- //
|
|
15
|
-
const state = proxy<EnsControllerState>({
|
|
16
|
-
loading: false
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
// -- Controller ---------------------------------------- //
|
|
20
|
-
export const EnsController = {
|
|
21
|
-
state,
|
|
22
|
-
|
|
23
|
-
subscribe(callback: (newState: EnsControllerState) => void) {
|
|
24
|
-
return sub(state, () => callback(state));
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
subscribeKey<K extends StateKey>(key: K, callback: (value: EnsControllerState[K]) => void) {
|
|
28
|
-
return subKey(state, key, callback);
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
async resolveName(name: string) {
|
|
32
|
-
try {
|
|
33
|
-
return await BlockchainApiController.lookupEnsName(name);
|
|
34
|
-
} catch (e) {
|
|
35
|
-
const error = e as BlockchainApiEnsError;
|
|
36
|
-
throw new Error(error?.reasons?.[0]?.description || 'Error resolving name');
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
};
|
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
import { subscribeKey as subKey } from 'valtio/vanilla/utils';
|
|
2
|
-
import { proxy, ref, subscribe as sub } from 'valtio/vanilla';
|
|
3
|
-
import { ContractUtil, type Balance } from '@reown/appkit-common-react-native';
|
|
4
|
-
import { AccountController } from './AccountController';
|
|
5
|
-
import { ConnectionController } from './ConnectionController';
|
|
6
|
-
import { SnackController } from './SnackController';
|
|
7
|
-
import { CoreHelperUtil } from '../utils/CoreHelperUtil';
|
|
8
|
-
import { EventsController } from './EventsController';
|
|
9
|
-
import { NetworkController } from './NetworkController';
|
|
10
|
-
import { RouterController } from './RouterController';
|
|
11
|
-
|
|
12
|
-
// -- Types --------------------------------------------- //
|
|
13
|
-
export interface TxParams {
|
|
14
|
-
receiverAddress: string;
|
|
15
|
-
sendTokenAmount: number;
|
|
16
|
-
gasPrice: bigint;
|
|
17
|
-
decimals: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface ContractWriteParams {
|
|
21
|
-
receiverAddress: string;
|
|
22
|
-
tokenAddress: string;
|
|
23
|
-
sendTokenAmount: number;
|
|
24
|
-
decimals: string;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface SendControllerState {
|
|
28
|
-
token?: Balance;
|
|
29
|
-
sendTokenAmount?: number;
|
|
30
|
-
receiverAddress?: string;
|
|
31
|
-
receiverProfileName?: string;
|
|
32
|
-
receiverProfileImageUrl?: string;
|
|
33
|
-
gasPrice?: bigint;
|
|
34
|
-
gasPriceInUSD?: number;
|
|
35
|
-
loading: boolean;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
type StateKey = keyof SendControllerState;
|
|
39
|
-
|
|
40
|
-
// -- State --------------------------------------------- //
|
|
41
|
-
const state = proxy<SendControllerState>({
|
|
42
|
-
loading: false
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// -- Controller ---------------------------------------- //
|
|
46
|
-
export const SendController = {
|
|
47
|
-
state,
|
|
48
|
-
|
|
49
|
-
subscribe(callback: (newState: SendControllerState) => void) {
|
|
50
|
-
return sub(state, () => callback(state));
|
|
51
|
-
},
|
|
52
|
-
|
|
53
|
-
subscribeKey<K extends StateKey>(key: K, callback: (value: SendControllerState[K]) => void) {
|
|
54
|
-
return subKey(state, key, callback);
|
|
55
|
-
},
|
|
56
|
-
|
|
57
|
-
setToken(token: SendControllerState['token']) {
|
|
58
|
-
if (token) {
|
|
59
|
-
state.token = ref(token);
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
|
|
63
|
-
setTokenAmount(sendTokenAmount: SendControllerState['sendTokenAmount']) {
|
|
64
|
-
state.sendTokenAmount = sendTokenAmount;
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
setReceiverAddress(receiverAddress: SendControllerState['receiverAddress']) {
|
|
68
|
-
state.receiverAddress = receiverAddress;
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
setReceiverProfileImageUrl(
|
|
72
|
-
receiverProfileImageUrl: SendControllerState['receiverProfileImageUrl']
|
|
73
|
-
) {
|
|
74
|
-
state.receiverProfileImageUrl = receiverProfileImageUrl;
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
setReceiverProfileName(receiverProfileName: SendControllerState['receiverProfileName']) {
|
|
78
|
-
state.receiverProfileName = receiverProfileName;
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
setGasPrice(gasPrice: SendControllerState['gasPrice']) {
|
|
82
|
-
state.gasPrice = gasPrice;
|
|
83
|
-
},
|
|
84
|
-
|
|
85
|
-
setGasPriceInUsd(gasPriceInUSD: SendControllerState['gasPriceInUSD']) {
|
|
86
|
-
state.gasPriceInUSD = gasPriceInUSD;
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
setLoading(loading: SendControllerState['loading']) {
|
|
90
|
-
state.loading = loading;
|
|
91
|
-
},
|
|
92
|
-
|
|
93
|
-
sendToken() {
|
|
94
|
-
if (this.state.token?.address && this.state.sendTokenAmount && this.state.receiverAddress) {
|
|
95
|
-
state.loading = true;
|
|
96
|
-
EventsController.sendEvent({
|
|
97
|
-
type: 'track',
|
|
98
|
-
event: 'SEND_INITIATED',
|
|
99
|
-
properties: {
|
|
100
|
-
isSmartAccount: false,
|
|
101
|
-
token: this.state.token.address,
|
|
102
|
-
amount: this.state.sendTokenAmount,
|
|
103
|
-
network: NetworkController.state.caipNetwork?.id || ''
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
this.sendERC20Token({
|
|
107
|
-
receiverAddress: this.state.receiverAddress,
|
|
108
|
-
tokenAddress: this.state.token.address,
|
|
109
|
-
sendTokenAmount: this.state.sendTokenAmount,
|
|
110
|
-
decimals: this.state.token.quantity.decimals
|
|
111
|
-
});
|
|
112
|
-
} else if (
|
|
113
|
-
this.state.receiverAddress &&
|
|
114
|
-
this.state.sendTokenAmount &&
|
|
115
|
-
this.state.gasPrice &&
|
|
116
|
-
this.state.token?.quantity.decimals
|
|
117
|
-
) {
|
|
118
|
-
state.loading = true;
|
|
119
|
-
EventsController.sendEvent({
|
|
120
|
-
type: 'track',
|
|
121
|
-
event: 'SEND_INITIATED',
|
|
122
|
-
properties: {
|
|
123
|
-
isSmartAccount: false,
|
|
124
|
-
token: this.state.token?.symbol,
|
|
125
|
-
amount: this.state.sendTokenAmount,
|
|
126
|
-
network: NetworkController.state.caipNetwork?.id || ''
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
this.sendNativeToken({
|
|
130
|
-
receiverAddress: this.state.receiverAddress,
|
|
131
|
-
sendTokenAmount: this.state.sendTokenAmount,
|
|
132
|
-
gasPrice: this.state.gasPrice,
|
|
133
|
-
decimals: this.state.token.quantity.decimals
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
|
|
138
|
-
async sendNativeToken(params: TxParams) {
|
|
139
|
-
RouterController.pushTransactionStack({
|
|
140
|
-
view: 'Account',
|
|
141
|
-
goBack: false
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
const to = params.receiverAddress as `0x${string}`;
|
|
145
|
-
const address = AccountController.state.address as `0x${string}`;
|
|
146
|
-
const value = ConnectionController.parseUnits(
|
|
147
|
-
params.sendTokenAmount.toString(),
|
|
148
|
-
Number(params.decimals)
|
|
149
|
-
);
|
|
150
|
-
const data = '0x';
|
|
151
|
-
|
|
152
|
-
try {
|
|
153
|
-
await ConnectionController.sendTransaction({
|
|
154
|
-
to,
|
|
155
|
-
address,
|
|
156
|
-
data,
|
|
157
|
-
value,
|
|
158
|
-
gasPrice: params.gasPrice
|
|
159
|
-
});
|
|
160
|
-
SnackController.showSuccess('Transaction started');
|
|
161
|
-
EventsController.sendEvent({
|
|
162
|
-
type: 'track',
|
|
163
|
-
event: 'SEND_SUCCESS',
|
|
164
|
-
properties: {
|
|
165
|
-
isSmartAccount: false,
|
|
166
|
-
token: this.state.token?.symbol || '',
|
|
167
|
-
amount: params.sendTokenAmount,
|
|
168
|
-
network: NetworkController.state.caipNetwork?.id || ''
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
this.resetSend();
|
|
172
|
-
} catch (error) {
|
|
173
|
-
state.loading = false;
|
|
174
|
-
EventsController.sendEvent({
|
|
175
|
-
type: 'track',
|
|
176
|
-
event: 'SEND_ERROR',
|
|
177
|
-
properties: {
|
|
178
|
-
isSmartAccount: false,
|
|
179
|
-
token: this.state.token?.symbol || '',
|
|
180
|
-
amount: params.sendTokenAmount,
|
|
181
|
-
network: NetworkController.state.caipNetwork?.id || ''
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
SnackController.showError('Something went wrong');
|
|
185
|
-
}
|
|
186
|
-
},
|
|
187
|
-
|
|
188
|
-
async sendERC20Token(params: ContractWriteParams) {
|
|
189
|
-
RouterController.pushTransactionStack({
|
|
190
|
-
view: 'Account',
|
|
191
|
-
goBack: false
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
const amount = ConnectionController.parseUnits(
|
|
195
|
-
params.sendTokenAmount.toString(),
|
|
196
|
-
Number(params.decimals)
|
|
197
|
-
);
|
|
198
|
-
|
|
199
|
-
try {
|
|
200
|
-
if (
|
|
201
|
-
AccountController.state.address &&
|
|
202
|
-
params.sendTokenAmount &&
|
|
203
|
-
params.receiverAddress &&
|
|
204
|
-
params.tokenAddress
|
|
205
|
-
) {
|
|
206
|
-
const tokenAddress = CoreHelperUtil.getPlainAddress(
|
|
207
|
-
params.tokenAddress as `${string}:${string}:${string}`
|
|
208
|
-
) as `0x${string}`;
|
|
209
|
-
await ConnectionController.writeContract({
|
|
210
|
-
fromAddress: AccountController.state.address as `0x${string}`,
|
|
211
|
-
tokenAddress,
|
|
212
|
-
receiverAddress: params.receiverAddress as `0x${string}`,
|
|
213
|
-
tokenAmount: amount,
|
|
214
|
-
method: 'transfer',
|
|
215
|
-
abi: ContractUtil.getERC20Abi(tokenAddress)
|
|
216
|
-
});
|
|
217
|
-
SnackController.showSuccess('Transaction started');
|
|
218
|
-
this.resetSend();
|
|
219
|
-
}
|
|
220
|
-
} catch (error) {
|
|
221
|
-
state.loading = false;
|
|
222
|
-
SnackController.showError('Something went wrong');
|
|
223
|
-
}
|
|
224
|
-
},
|
|
225
|
-
|
|
226
|
-
resetSend() {
|
|
227
|
-
state.token = undefined;
|
|
228
|
-
state.sendTokenAmount = undefined;
|
|
229
|
-
state.receiverAddress = undefined;
|
|
230
|
-
state.receiverProfileImageUrl = undefined;
|
|
231
|
-
state.receiverProfileName = undefined;
|
|
232
|
-
state.loading = false;
|
|
233
|
-
}
|
|
234
|
-
};
|