of_the_double_string static method

IcpTokens of_the_double_string(
  1. String icp_string
)

Implementation

static IcpTokens of_the_double_string(String icp_string) {
    icp_string = icp_string.trim();
    if (icp_string == '') {
        throw Exception('must be a number');
    }
    List<String> icp_string_split = icp_string.split('.');
    if (icp_string_split.length > 2) {
        throw Exception('invalid number.');
    }
    BigInt icp = BigInt.parse(icp_string_split[0]);
    BigInt icp_e8s_less_than_1 = BigInt.from(0);
    if (icp_string_split.length == 2) {
        String decimal_places = icp_string_split[1];
        if (decimal_places.length > IcpTokens.DECIMAL_PLACES) {
            throw Exception('Max ${IcpTokens.DECIMAL_PLACES} decimal places for the IcpTokens');
        }
        while (decimal_places.length < IcpTokens.DECIMAL_PLACES) {
            decimal_places = '${decimal_places}0';
        }
        icp_e8s_less_than_1 = BigInt.parse(decimal_places);
    }
    IcpTokens icptokens = IcpTokens(e8s: (icp * IcpTokens.DIVIDABLE_BY) + icp_e8s_less_than_1);
    return icptokens;
}