Skip to content

Commit 32742ba

Browse files
committed
Added ERC20 transfer.(#11)
1 parent 6e98c95 commit 32742ba

12 files changed

Lines changed: 55 additions & 49 deletions

File tree

lib/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ afterEvaluate {
7878
from(components["release"])
7979
groupId = "com.github.dora4"
8080
artifactId = "dora-walletconnect-support"
81-
version = "2.1.9"
81+
version = "2.1.10"
8282
}
8383
}
8484
}

lib/src/main/java/dora/pay/DoraFund.kt

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ object DoraFund {
676676
positiveButton(context.getString(R.string.pay))
677677
positiveListener {
678678
Web3Modal.getAccount()?.let { session ->
679-
sendRawTransactionRequest(context, accessKey, secretKey, session.address, account,
679+
sendNativeTransactionRequest(context, accessKey, secretKey, session.address, account,
680680
PayUtils.convertToHexWei(value), gasLimit, gasPrice, "", "",
681681
onSuccess = {
682682
if (it is SentRequestResult.WalletConnect) {
@@ -686,7 +686,7 @@ object DoraFund {
686686
},
687687
onError = {
688688
ToastUtils.showShort(R.string.payment_failed)
689-
Log.e("sendTransactionRequest", it.toString())
689+
Log.e("sendNativeTransactionRequest", it.toString())
690690
}
691691
)
692692
}
@@ -721,7 +721,7 @@ object DoraFund {
721721
positiveButton(context.getString(R.string.pay))
722722
positiveListener {
723723
Web3Modal.getAccount()?.let { session ->
724-
sendRawTransactionRequest(context, accessKey, secretKey, session.address, account,
724+
sendNativeTransactionRequest(context, accessKey, secretKey, session.address, account,
725725
PayUtils.convertToHexWei(value), gasLimit, "", maxFeePerGas, maxPriorityFeePerGas,
726726
onSuccess = {
727727
if (it is SentRequestResult.WalletConnect) {
@@ -731,7 +731,7 @@ object DoraFund {
731731
},
732732
onError = {
733733
ToastUtils.showShort(R.string.payment_failed)
734-
Log.e("sendTransactionRequest", it.toString())
734+
Log.e("sendNativeTransactionRequest", it.toString())
735735
}
736736
)
737737
}
@@ -781,7 +781,7 @@ object DoraFund {
781781
secretKey,
782782
session.address,
783783
toAddress,
784-
PayUtils.convertToHexWeiABI(amount),
784+
PayUtils.convertToHexWeiABI(amount, token.decimals),
785785
token.symbol,
786786
token.contractAddress,
787787
gasLimit,
@@ -806,7 +806,7 @@ object DoraFund {
806806
secretKey,
807807
session.address,
808808
toAddress,
809-
PayUtils.convertToHexWeiABI(amount),
809+
PayUtils.convertToHexWeiABI(amount, token.decimals),
810810
token.symbol,
811811
token.contractAddress,
812812
gasLimit,
@@ -837,8 +837,8 @@ object DoraFund {
837837
* @since 2.0
838838
*/
839839
@Deprecated(
840-
message = "This method is deprecated, use the sendRawTransactionRequest() instead",
841-
replaceWith = ReplaceWith("sendRawTransactionRequest(context,accessKey,secretKey," +
840+
message = "This method is deprecated, use the sendNativeTransactionRequest() instead",
841+
replaceWith = ReplaceWith("sendNativeTransactionRequest(context,accessKey,secretKey," +
842842
"from,to,value,gasLimit,gasPrice,maxFeePerGas,maxPriorityFeePerGas,onSuccess,onError)"),
843843
level = DeprecationLevel.WARNING
844844
)
@@ -900,10 +900,10 @@ object DoraFund {
900900
}
901901

902902
/**
903-
* Send raw transaction request.
903+
* Send native transaction request.
904904
* @since 2.1
905905
*/
906-
private fun sendRawTransactionRequest(
906+
private fun sendNativeTransactionRequest(
907907
context: Context,
908908
accessKey: String,
909909
secretKey: String,
@@ -930,32 +930,32 @@ object DoraFund {
930930
ToastUtils.showShort("Account is null")
931931
return
932932
}
933-
val status = nativeSendRawTransactionRequest(context, accessKey, secretKey, from, to,
933+
val status = nativeSendNativeTransactionRequest(context, accessKey, secretKey, from, to,
934934
value, gasLimit, gasPrice, maxFeePerGas, maxPriorityFeePerGas, onSuccess, onError)
935935
when (status) {
936936
STATUS_CODE_OK -> {
937-
Log.i("sendTransactionRequest", "OK.")
937+
Log.i("sendNativeTransactionRequest", "OK.")
938938
}
939939
STATUS_CODE_ACCESS_KEY_IS_INVALID -> {
940-
Log.e("sendTransactionRequest", "The access key is invalid.")
940+
Log.e("sendNativeTransactionRequest", "The access key is invalid.")
941941
}
942942
STATUS_CODE_PAYMENT_ERROR -> {
943-
Log.e("sendTransactionRequest", "Payment error, please try again.")
943+
Log.e("sendNativeTransactionRequest", "Payment error, please try again.")
944944
}
945945
STATUS_CODE_SINGLE_TRANSACTION_LIMIT -> {
946-
Log.e("sendTransactionRequest", "Single transaction limit exceeded.")
946+
Log.e("sendNativeTransactionRequest", "Single transaction limit exceeded.")
947947
}
948948
STATUS_CODE_MONTHLY_LIMIT -> {
949-
Log.e("sendTransactionRequest", "Monthly limit exceeded.")
949+
Log.e("sendNativeTransactionRequest", "Monthly limit exceeded.")
950950
}
951951
STATUS_CODE_UNSUPPORTED_CHAIN_ID -> {
952-
Log.e("sendTransactionRequest", "Unsupported chainId.")
952+
Log.e("sendNativeTransactionRequest", "Unsupported chainId.")
953953
}
954954
STATUS_CODE_FAILED_TO_FETCH_TOKEN_PRICE -> {
955-
Log.e("sendTransactionRequest", "Failed to fetch token price.")
955+
Log.e("sendNativeTransactionRequest", "Failed to fetch token price.")
956956
}
957957
STATUS_CODE_ACCESS_KEY_IS_EXPIRED -> {
958-
Log.e("sendTransactionRequest", "The access key is expired.")
958+
Log.e("sendNativeTransactionRequest", "The access key is expired.")
959959
}
960960
}
961961
} catch (e: Exception) {
@@ -1034,8 +1034,8 @@ object DoraFund {
10341034
* @since 2.0
10351035
*/
10361036
@Deprecated(
1037-
message = "This method is deprecated, use the nativeSendRawTransactionRequest() instead",
1038-
replaceWith = ReplaceWith("nativeSendRawTransactionRequest(context,accessKey," +
1037+
message = "This method is deprecated, use the nativeSendNativeTransactionRequest() instead",
1038+
replaceWith = ReplaceWith("nativeSendNativeTransactionRequest(context,accessKey," +
10391039
"secretKey,from,to,value,gasLimit,gasPrice,maxFeePerGas,maxPriorityFeePerGas," +
10401040
"onSuccess,onError)"),
10411041
level = DeprecationLevel.WARNING
@@ -1054,10 +1054,10 @@ object DoraFund {
10541054
): Int
10551055

10561056
/**
1057-
* Native layer handles sending raw transaction requests.
1057+
* Native layer handles sending native transaction requests.
10581058
* @since 2.1
10591059
*/
1060-
private external fun nativeSendRawTransactionRequest(
1060+
private external fun nativeSendNativeTransactionRequest(
10611061
context: Context,
10621062
accessKey: String,
10631063
secretKey: String,

lib/src/main/java/dora/pay/PayUtils.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ object PayUtils {
3636
* @since 2.1
3737
*/
3838
@JvmStatic
39-
fun convertToHexWeiABI(amount: Double): String {
40-
val weiValue = BigDecimal(amount).multiply(BigDecimal.TEN.pow(18)).toBigInteger()
39+
fun convertToHexWeiABI(amount: Double, decimals: Int = 18): String {
40+
val decimalAmount = BigDecimal.valueOf(amount)
41+
val weiValue = decimalAmount.multiply(BigDecimal.TEN.pow(decimals)).toBigInteger()
4142
val hex = weiValue.toString(16)
4243
return hex.padStart(64, '0')
4344
}
4445

45-
4646
/**
4747
* Query blockchain data to check whether the transaction
4848
* has been successfully confirmed on-chain.

lib/src/main/java/dora/pay/token/ArbitrumToken.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ object ArbitrumToken {
1212
* @since 2.1
1313
*/
1414
@JvmField
15-
val USDT = Token(EVMChains.ARBITRUM, "USDT", "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9")
15+
val USDT = Token(EVMChains.ARBITRUM, "USDT", "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9", 6)
1616

1717
/**
1818
* @since 2.1
1919
*/
2020
@JvmField
21-
val USDC = Token(EVMChains.ARBITRUM, "USDC", "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8")
21+
val USDC = Token(EVMChains.ARBITRUM, "USDC", "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8", 6)
2222

2323
/**
2424
* @since 2.1
2525
*/
2626
@JvmField
27-
val DAI = Token(EVMChains.ARBITRUM, "DAI", "0xda10009cbd5d07dd0cecc66161fc93d7c9000da1")
27+
val DAI = Token(EVMChains.ARBITRUM, "DAI", "0xda10009cbd5d07dd0cecc66161fc93d7c9000da1", 18)
2828
}

lib/src/main/java/dora/pay/token/AvalancheToken.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ object AvalancheToken {
1212
* @since 2.1
1313
*/
1414
@JvmField
15-
val USDT = Token(EVMChains.AVALANCHE, "USDT", "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7")
15+
val USDT = Token(EVMChains.AVALANCHE, "USDT", "0x9702230A8Ea53601f5cD2dc00fDBc13d4dF4A8c7", 6)
1616

1717
/**
1818
* @since 2.1
1919
*/
2020
@JvmField
21-
val USDC = Token(EVMChains.AVALANCHE, "USDC", "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E")
21+
val USDC = Token(EVMChains.AVALANCHE, "USDC", "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E", 6)
2222

2323
/**
2424
* @since 2.1
2525
*/
2626
@JvmField
27-
val DAI = Token(EVMChains.AVALANCHE, "DAI", "0xd586E7F844cEa2F87f50152665BCbc2C279D8d70")
27+
val DAI = Token(EVMChains.AVALANCHE, "DAI", "0xd586E7F844cEa2F87f50152665BCbc2C279D8d70", 18)
2828
}

lib/src/main/java/dora/pay/token/BscToken.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ object BscToken {
1212
* @since 2.1
1313
*/
1414
@JvmField
15-
val USDT = Token(EVMChains.BSC, "USDT", "0x55d398326f99059fF775485246999027B3197955")
15+
val USDT = Token(EVMChains.BSC, "USDT", "0x55d398326f99059fF775485246999027B3197955", 6)
1616

1717
/**
1818
* @since 2.1
1919
*/
2020
@JvmField
21-
val USDC = Token(EVMChains.BSC, "USDC", "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d")
21+
val USDC = Token(EVMChains.BSC, "USDC", "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d", 6)
2222

2323
/**
2424
* @since 2.1
2525
*/
2626
@JvmField
27-
val DAI = Token(EVMChains.BSC, "DAI", "0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3")
27+
val DAI = Token(EVMChains.BSC, "DAI", "0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3", 18)
2828
}

lib/src/main/java/dora/pay/token/EthereumToken.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ object EthereumToken {
1212
* @since 2.1
1313
*/
1414
@JvmField
15-
val USDT = Token(EVMChains.ETHEREUM, "USDT", "0xdAC17F958D2ee523a2206206994597C13D831ec7")
15+
val USDT = Token(EVMChains.ETHEREUM, "USDT", "0xdAC17F958D2ee523a2206206994597C13D831ec7", 6)
1616

1717
/**
1818
* @since 2.1
1919
*/
2020
@JvmField
21-
val USDC = Token(EVMChains.ETHEREUM, "USDC", "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48")
21+
val USDC = Token(EVMChains.ETHEREUM, "USDC", "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", 6)
2222

2323
/**
2424
* @since 2.1
2525
*/
2626
@JvmField
27-
val DAI = Token(EVMChains.ETHEREUM, "DAI", "0x6B175474E89094C44Da98b954EedeAC495271d0F")
27+
val DAI = Token(EVMChains.ETHEREUM, "DAI", "0x6B175474E89094C44Da98b954EedeAC495271d0F", 18)
2828
}

lib/src/main/java/dora/pay/token/OptimismToken.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ object OptimismToken {
1212
* @since 2.1
1313
*/
1414
@JvmField
15-
val USDT = Token(EVMChains.OPTIMISM, "USDT", "0x94b008aA00579c1307B0EF2c499aD98a8ce58e58")
15+
val USDT = Token(EVMChains.OPTIMISM, "USDT", "0x94b008aA00579c1307B0EF2c499aD98a8ce58e58", 6)
1616

1717
/**
1818
* @since 2.1
1919
*/
2020
@JvmField
21-
val USDC = Token(EVMChains.OPTIMISM, "USDC", "0x7F5c764cBc14f9669B88837ca1490cCa17c31607")
21+
val USDC = Token(EVMChains.OPTIMISM, "USDC", "0x7F5c764cBc14f9669B88837ca1490cCa17c31607", 6)
2222

2323
/**
2424
* @since 2.1
2525
*/
2626
@JvmField
27-
val DAI = Token(EVMChains.OPTIMISM, "DAI", "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1")
27+
val DAI = Token(EVMChains.OPTIMISM, "DAI", "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1", 18)
2828
}

lib/src/main/java/dora/pay/token/PolygonToken.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ object PolygonToken {
1212
* @since 2.1
1313
*/
1414
@JvmField
15-
val USDT = Token(EVMChains.POLYGON, "USDT", "0x3813e82e6f7098b9583FC0F33a962D02018B6803")
15+
val USDT = Token(EVMChains.POLYGON, "USDT", "0x3813e82e6f7098b9583FC0F33a962D02018B6803", 6)
1616

1717
/**
1818
* @since 2.1
1919
*/
2020
@JvmField
21-
val USDC = Token(EVMChains.POLYGON, "USDC", "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174")
21+
val USDC = Token(EVMChains.POLYGON, "USDC", "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174", 6)
2222

2323
/**
2424
* @since 2.1
2525
*/
2626
@JvmField
27-
val DAI = Token(EVMChains.POLYGON, "DAI", "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063")
27+
val DAI = Token(EVMChains.POLYGON, "DAI", "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063", 18)
2828
}

lib/src/main/java/dora/pay/token/Token.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ import com.walletconnect.web3.modal.client.Modal
55
/**
66
* Represents an ERC20 token on an EVM-compatible chain.
77
*
8-
* @property chain The chain the token belongs to (e.g., Polygon, Ethereum, BSC, Arbitrum)
9-
* @property symbol The symbol of the token (e.g., "USDT", "ETH", "DAI").
10-
* @property contractAddress The token's contract address
8+
* @property chain The blockchain the token belongs to (e.g., Polygon, Ethereum, BSC, Arbitrum).
9+
* @property symbol The symbol of the token (e.g., "USDT", "USDC", "DAI").
10+
* @property contractAddress The token's smart contract address on the chain.
11+
* @property decimals The number of decimal places used by the token (used for converting human-readable amounts to integer units).
1112
* @since 2.1
1213
*/
13-
open class Token(val chain: Modal.Model.Chain, val symbol: String, val contractAddress: String)
14+
open class Token(
15+
val chain: Modal.Model.Chain,
16+
val symbol: String,
17+
val contractAddress: String,
18+
val decimals: Int
19+
)

0 commit comments

Comments
 (0)